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

解决方案 »

  1.   

    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大致就这个思路
      

  2.   

    你这样category3为空的,好象没显示吧。
    categoryDesc  NORMAL  WARNING  MAJOR  total
    category3     0       0        0      0,
      

  3.   

    select c.descripiton categoryDesc,c.NORMAL NORMAL,c.WARNING  WARNING,c.MAJOR  MAJOR,sum(*) total from detailTable a,categoryTable b,severityTable c where a.categoryid =b.categoryid and c.severityId=a.severityId
    个人见解  请自己测试。。
      

  4.   

    再提一个要求 
              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