select at.typeName "事故类型", count(at.typeName) "事故次数", sum(au.deathCount) "死亡人数"
from acciedntType at, accident a, acciedntUser au
where at.id(+) = a.atypeid and a.aID (+) = au.aID
group by at.typeName

解决方案 »

  1.   

    忘了用nvl
    select at.typeName "事故类型", nvl(count(at.typeName), 0) "事故次数", nvl(sum(au.deathCount), 0) "死亡人数"
    from acciedntType at, accident a, acciedntUser au
    where at.id(+) = a.atypeid and a.aID (+) = au.aID
    group by at.typeName;
      

  2.   

    try:select a.typeName,nvl(d.n,0) sgcs,nvl(d.dcc,0) swrs 
    from acciedntType a,
    (select atypeid,count(*) n,sum(dc) dcc from acciednt b ,
        (select aID,sum(deathCount) dc from acciedntUser) c
     where b.aID=c.aID) d
    where a.id=d.atypeid(+);
      

  3.   

    select typeName "事故类型", count(aname)"事故次数", sum(death)"死亡人数"  from( 
    select  at.typeName,a.aname,user.deathfrom accident a, acciedntType at,(select aID,sum(deathCount) death from acciedntUser group by aID) userwhere user.aID=a.aID and a.atypeid=b.id
    )group by typeName
      

  4.   

    SORRY!都忘了GROUP BY
    :(select a.typeName,nvl(d.n,0) sgcs,nvl(d.dcc,0) swrs 
    from acciedntType a,
    (select atypeid,count(*) n,sum(dc) dcc from acciednt b ,
        (select aID,sum(deathCount) dc from acciedntUser group by aID) c
     where b.aID=c.aID group by atypeid) d
    where a.id=d.atypeid(+);
      

  5.   

    好像没用,如果同一个交通事故对应两条伤亡人员记录的话事故次数就会变成2,对应的伤亡人数也会翻倍
    ------------------------------------------------------
    不懂。楼主数据不就是要的到
    3.人员死亡表(acciedntUser)uid   aID(事故ID)     deathCount(死亡人数)
    1      1                5
    2      3                20
    3      3                5
    4      1                5这样算重复了吗?事故类型   事故次数    死亡人数 交通事故     2          10
    设备事故     2          25
    环境事故     0          0
    火灾事故     0          0
    其他事故     0          0