case when 的简单使用:
如:
1 SELECT BAE001, 2 (CASE AAE180 3 WHEN 30 THEN 4 '学生' 5 WHEN 104 THEN 6 '低保,残疾' 7 WHEN 160 THEN 8 '成年人' 9 END) AAE180, 10 COUNT(DISTINCT(AAC001)) aac001 11 FROM SKC84 12 WHERE AAE140 IN ('340', '350') 13 AND AAE341 = '0' 14 AND AAE180 IN (30, 104, 160) 15 GROUP BY BAE001, AAE180 16 ORDER BY BAE001;
查询结果: