我正在从以下查询中查询数据
select count(*) as Total, slabreached
from mwp_main
where
problemsince >= current timestamp - 7 days
and problemsince < current timestamp
and status not in ('OPEN','REASSIGNED','REASSIGNED RESPONSE','REOPEN')
group by slabreached
上面的查询返回以下结果
TOTAL SLABREACHED
93 0
7 1
SLABREACHED
仅包含 0
s 和 1
s。
但是我想在我的选择查询中用SLABREACHED
替换0
,用WithInSLA
替换1
,因为我无法更改数据集。
任何帮助将不胜感激。
您可以使用
CASE WHEN
表达式尝试以下操作
select count(*) as Total,case when SLABREACHED=0 then 'SLABREACHED'
when SLABREACHED=1 then 'WithInSLA' end as SLABREACHED
from mwp_main
where problemsince >= current timestamp - 7 days and problemsince < current timestamp
and status not in ('OPEN','REASSIGNED','REASSIGNED RESPONSE','REOPEN')
group by slabreached
我很好奇你为什么不希望结果在一行中:
select sum(SLABREACHED) as WithInSLA,
sum(1 - SLABREACHED) as SLABREACHED
from mwp_main
where problemsince >= current timestamp - 7 days and
problemsince < current timestamp and
status not in ('OPEN', 'REASSIGNED',' REASSIGNED RESPONSE', 'REOPEN') ;