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_IDINVOICE_ID
A112343214
A556113214
A99867NULL
A556713214
A88907NULL
A560126701

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_IDINVOICE COUNT
32143
NULL2
67011

Updated on: 14-Sep-2020

292 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements