Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I have a table

create table us

(

 a number

);

Now I have data like:

a

1

2

3

4

null

null

null

8

9

Now I need a single query to count null and not null values in column a

1 Answer

0 votes
by (40.7k points)

The below code will work for Oracle and SQL Server:

select sum(case when a is null then 1 else 0 end) count_nulls

     , count(a) count_not_nulls 

  from us;

Otherwise, you can use this:

select count(*) - count(a), count(a) from us;

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...