Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
What is the result of count function in the NULL value present in DB2 table?
The COUNT function in DB2 is used to return the number of rows which satisfies the given criteria. The GROUP BY is used to divide the rows in the groups based on the criteria given in the query.
If we perform the GROUP BY on INVOICE_ID and there are few rows having NULL value in INVOICE_ID then the null values form a separate group. For example, if we have below table.
| ORDER_ID | INVOICE_ID |
|---|---|
| A11234 | 3214 |
| A55611 | 3214 |
| A99867 | NULL |
| A55671 | 3214 |
| A88907 | NULL |
| A56012 | 6701 |
On executing the query which performs GROUP BY on INVOICE_ID and counts the number of rows, we will get the result below.
SELECT INVOICE_ID, COUNT(*) AS INVOICE COUNT FROM ORDERS GROUP BY INVOICE_ID;
| INVOICE_ID | INVOICE COUNT |
|---|---|
| 3214 | 3 |
| NULL | 2 |
| 6701 | 1 |
Advertisements
