i'm new sql , i'm having trouble count query. want count number of results return value , return second count if value null.
here have far. if can appreciate it. thanks.
select sum(case when column name = '!null' 1 else 0 end) [policy id], sum(case when column name = 'null' 1 else 0 end) [no policy id] --count(*) [total] table.name columnname >= '2016-01-01'
use is null
, is not null
instead of checking nulls equality:
select sum(case when column_name not null 1 else 0 end) [policy id], sum(case when column_name null 1 else 0 end) [no policy id] --count(*) [total] table.name columnname >= '2016-01-01'
in sql value null
means "unknown" , hence comparing column value against using =
yields unknown result. instead, use is null
or is not null
.
Comments
Post a Comment