Reputation: 17724
Pandas is offering
df.isnull().sum()
to count the NAN values per each column. Is there something similar in SQL?
Upvotes: 1
Views: 2599
Reputation: 168671
You can use:
SELECT COUNT(*) - COUNT(column_name)
FROM table_name
COUNT(*)
(or, equivalently, COUNT(1)
) will count rows regardless of whether any columns have NULL
values and COUNT(column_name)
will count the non-NULL
values (and, if it exists, can use an index on that column).
Upvotes: 1
Reputation: 146630
No idea what Pandas is but good old CASE
should do (and it works in all major database engines):
SELECT COUNT(CASE WHEN column_name IS NULL THEN 1 END) ...
Upvotes: 1