Reputation: 587
I have a query similar to this:
select distinct 'density' as feature, density as value,
count(density) as frequency
from cases
where density in not null;
Let's call it query A, and the next query is query B.
In the case when the query B:
select distinct density as value, count(density) as frequency
from cases
where density in not null;
returns nothing, query A returns a line contains:
('density', null, null)
but I want from query A to return nothing. The question is, how to refactor the query A to force it to return nothing in the explained case?
Upvotes: 0
Views: 171
Reputation: 1269563
Try doing this:
select 'density' as feature, density as value,
count(density) as frequency
from cases
where density is not null
group by density;
If all the rows are filtered out by the where
, then the group by
will return no rows at all.
Upvotes: 1