SUM() vs COUNT()
SELECT
----1---- (CASE
WHEN album_name IS NULL THEN 1
ELSE 0
END) AS count_nulls
FROM
albums;
Can someone explain to me the difference between using sum and using count in 1 before the case subquery?
1 answers ( 0 marked as helpful)
Hi Heba!
Thanks for reaching out.
The COUNT() function is used to count the number of rows for a given condition. The COUNT() function works on numeric as well as non-numeric values. The SUM() function is used to calculate the total sum of all values in the specified numeric column. So, we need to use the SUM() function in this case.
Hope this helps.
Best,
Tsvetelin