SELECT
CASE WHEN type IN 'Updates','Multibases' THEN 'Updates' ELSE type END as TYPE,
SUM(Update_Count)
FROM
Scope1
WHERE
type in ('Updates','Multibases','DAIS','Acds','Legis','LegAll')
and (RECVD_DATE >='04/02/2012' and RECVD_DATE <='11/30/2012')
GROUP BY
CASE WHEN type IN 'Updates','Multibases' THEN 'Updates' ELSE type END
一个更具可扩展性的解决方案是让另一个表映射type
到super_type
.
SELECT
map.super_type,
SUM(Scope1.update_count)
FROM
Scope1
INNER JOIN
map
ON map.type = Scope1.type
WHERE
Scope1.type in ('Updates','Multibases','DAIS','Acds','Legis','LegAll')
and Scope1.RECVD_DATE >='04/02/2012'
and Scope1.RECVD_DATE <='11/30/2012'
GROUP BY
map.super_type
然后你可以在你的地图中放置如下条目......
type | super_type
------------+------------
Legis | Legis
Acds | Acds
Updates | Updates
Multibases | Updates
等等等等