我正在从以下查询中查询数据
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
和1
s。
但是我想在我的选择查询中将0
替换为SLABREACHED
,将1
替换为WithInSLA
,因为我无法更改数据集。
任何帮助将不胜感激。
答案 0 :(得分: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
答案 1 :(得分:0)
我很好奇为什么不希望将结果放在一行中
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') ;