
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Result of COUNT Function on NULL Values 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