我有一个mysql查询:
select count(srcount) as SR_Count,
CASE assignee_name
when 'U80040300' then 'ABC'
when 'U80036396' then 'DEF'
when 'U80035831' then 'GHI'
when 'U80042986' then 'JKL'
else 'A'
end as Guys_Name
from data
GROUP BY assignee_name;
其中输出为
SR_COUNT GUYS_NAME
3 A
5 A
3 GHI
2 DEF
3 ABC
2 JKL
但我希望输出为
SR_COUNT GUYS_NAME
8 A
3 GHI
2 DEF
3 ABC
2 JKL
以下是SQLFiddle
任何帮助将不胜感激。 提前谢谢..
答案 0 :(得分:2)
按Guys_Name
select count(srcount) as SR_Count,
CASE assignee_name
when 'U80040300' then 'ABC'
when 'U80036396' then 'DEF'
when 'U80035831' then 'GHI'
when 'U80042986' then 'JKL'
else 'A'
end as Guys_Name
from data
GROUP BY Guys_Name;
答案 1 :(得分:1)
select count(srcount) as SR_Count, guys_name
from
( select srcount,
CASE assignee_name
when 'U80040300' then 'ABC'
when 'U80036396' then 'DEF'
when 'U80035831' then 'GHI'
when 'U80042986' then 'JKL'
else 'A'
end as Guys_Name
from data ) as mydata
GROUP BY guys_name;
只需对您的案例结果进行分组。