我从员工表中获取各种状态,该员工表有230个记录,状态低于5。 我已经编写了查询以获取每个状态的计数但现在需要将状态A和B的组合计数为AB。
我的查询:
SELECT DISTINCT Status AS Status,
COUNT(Status ) AS StatusCount
FROM EMPLOYEE
GROUP BY Status
我的查询输出是:
Status Count
A 100
B 50
C 30
D 10
E 40
我希望结果为A& B组合并保持不变。
Status Count
A&B 150
C 30
D 10
E 40
答案 0 :(得分:1)
使用case
SELECT case when Status in ('A','B')
then 'A&B'
else Status
end AS Status,
COUNT(Status) AS StatusCount
FROM EMPLOYEE
GROUP BY case when Status in ('A','B')
then 'A&B'
else Status
end
答案 1 :(得分:1)
使用也可以使用decode
SELECT decode(status,'A','A&B','B','A&B',status) AS Status,
COUNT(status) AS StatusCount
FROM EMPLOYEE
GROUP BY decode(status,'A','A&B','B','A&B',status) AS Status