求一条报表sql
detailTable表
id categoryid severityId name
1 1 1 name1
2 1 2 name2
3 1 3 name3
4 2 1 name4
5 2 2 name5
6 2 2 name6
categoryTable表
categoryid descripiton
1 category1
2 category2
3 category3
severityTable表
severityId descripiton
1 NORMAL
2 WARNING
3 MAJOR
最后要求的查询结果如下:
categoryDesc NORMAL WARNING MAJOR total
category1 1 1 1 3
category2 1 2 0 3
category3 0 0 0 0
请赐sql
------解决方案--------------------select d.descripiton,
sum(decode(severityId,1,1,0)) normal,
sum(decode(severityId,2,1,0)) warning,
sum(decode(severityId,3,1,0)) major,
count(*)
from(select a.descripiton,c.severityId from categoryTable a,detailTable c
where a.categoryid = c.categoryid) d group by description
大致就这个思路