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?
它有效,但我很好奇是否可以使用“分组依据”来过滤空值和非空值?
1 个解决方案
#1
1
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
.
在这里我曾经使用过CASE WHEN。
#1
1
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
.
在这里我曾经使用过CASE WHEN。