sql 语句的使用  |
| By wjliu182 发表于 2006-8-4 14:17:54 |
现有表table结构如下:
a1(病房) a2(人数) a3(1代表爱滋病、1代表感冒、3代表骨折)
1001 5 1
1001 6 2
1001 7 3
为了得到以下查询信息
病房 爱滋病人数 感冒人数 骨折人数
1001 5 6 7
交叉表语句的实现:
--用于:交叉表的列数是确定的
select a1,sum(case a3 when 1 then a2 else 0 end) as '爱滋病',
sum(case a3 when 2 then a2 else 0 end) as '感冒',
sum(case a3 when 3 then a2 else 0 end) as '骨折'
from table
group by a1
|
| |
| 发表评论:
| |
|