In total there are 10 values in my table, 5 of which are null. I need to display the count using case statement in Oracle, like output below:
Sample Data:
+------+
| Eid |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| NULL |
| NULL |
| NULL |
| NULL |
| NULL |
+------+
Output:
+--------+--------+
| Eid | Counts |
+--------+--------+
| Number | 5 |
| Null | 5 |
+--------+--------+
Best Answer
This may not directly help you, since I only know SQL Server, but in any case this is how I would approach this:
Sample Data:
My idea revolves around the idea that
COUNT(column)
does not countNULLs
, whereasCOUNT(*)
does:Output 1:
If the specific arrangement of rows and columns is important, I would
UNPIVOT
:Output 2:
Using
CASE
Output 3:
Edit:
This is the query form Babu ended up using: