Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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.4k 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;

Browse Categories

...