Georg Heiler
Georg Heiler

Reputation: 17724

oracle count null per columns

Pandas is offering

df.isnull().sum()

to count the NAN values per each column. Is there something similar in SQL?

Upvotes: 1

Views: 2599

Answers (2)

MT0
MT0

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

Álvaro González
Álvaro González

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

Related Questions