Reputation: 89
At present, I have something like:
select sum(total) from table_name where field != ''
UNION
select sum(total) from table_name where field = ''
It works but I'm curious if it is possible to use "group by" to filter by empty and non-empty values?
Upvotes: 0
Views: 289
Reputation: 7937
select SUM(CASE WHEN field != '' THEN total ELSE 0) NONEMPTY,
SUM(CASE WHEN field = '' THEN total ELSE 0) EMPTY from table_name
Try above query.
Here i had used CASE WHEN
.
Upvotes: 1