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 name6categoryTable表
categoryid descripiton
1 category1
2 category2
3 category3severityTable表
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
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 name6categoryTable表
categoryid descripiton
1 category1
2 category2
3 category3severityTable表
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
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大致就这个思路
categoryDesc NORMAL WARNING MAJOR total
category3 0 0 0 0,
个人见解 请自己测试。。
categoryDesc NORMAL WARNING MAJOR total category1 1 1 1 3
category2 1 2 0 3
category1 0 0 0 0 sum 2 3 1 6
就是显示 最后一行,总共的sql