- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain SQL describing COUNT aggregate and CURRENT DATE function
Problem: Write a SQL query to count the number of orders which were placed today from the ORDERS DB2 table. (The date should not be hardcoded)
Solution
We can find the count of orders which are placed today using the below DB2 query:
Example
SELECT COUNT(ORDER_ID) AS ORDER_COUNT FROM ORDERS WHERE ORDER_DATE = CURRENT DATE
In this query, we have used the COUNT COLUMN function which will count the total number of ORDER_ID (primary key). In the WHERE clause, we will use the predicate for the ORDER_DATE column. The CURRENT DATE is a DB2 inbuilt function which will return the current system date.
For example, if we have below ORDERS DB2 table:
ORDER_ID | ORDER_TOTAL | ORDER_DATE |
Z22345 | 342 | 28-07-2020 |
Z62998 | 543 | 30-07-2020 |
Z56990 | 431 | 28-07-2020 |
Z56902 | 6743 | 29-07-2020 |
Z99781 | 443 | 27-07-2020 |
Z56112 | 889 | 30-07-2020 |
If the current date is 30-07-2020, then the query with CURRENT DATE predicate will return the below result:
ORDER_COUNT |
2 |
- Related Articles
- SQL query describing usage of SUM aggregate function and GROUP-BY with HAVING
- Example of SQL query describing COUNT function and GROUP BY
- What is the SQL query describing usage of MAX aggregate function and GROUP-BY with HAVING?
- Explain aggregate functions with the help of SQL queries
- Example of SQL query describing the conditional processing
- MySQL DATE function to return the difference between current date and joining date
- How to update column values with date records and set 1 for corresponding records before the current date in SQL
- Explain Get-Date function in PowerShell.
- Calling NOW() function to fetch current date records in MySQL?
- Explain the module function to split ABAP date?
- Select dates between current date and 3 months from the current date in MySQL?
- Current Date and Time in Perl
- Select aggregate function and all other columns in MySQL
- MySQL query to get current datetime and only current date
- MongoDB query to implement aggregate function

Advertisements