select a.deptname, b.personid, b.personname, c.money 
from 表A a, 表B b, 表C c 
where a.deptbh=b.depbh and b.personid=c.personidselect a.deptname, sum(c.money)
from 表A a, 表B b, 表C c 
where a.deptbh=b.depbh and b.personid=c.personid
group by a.deptname

解决方案 »

  1.   

    select a.deptname, b.personid, b.personname, c.money 
    from 表B b inner join 表A a on b.deptbh=a.deptbh
    inner join 表C c on  b.personid=c.personid
    select a.deptname,sum(c.moeny) money
    from 表B b inner join 表A a on b.deptbh=a.deptbh
    inner join 表C c on  b.personid=c.personid
    group by a.deptname
      

  2.   

    select A.deptname, B.personid, B.personname, C.money from B 
     left join A on A.deptbh = B.deptbh
     left join C on C.personid = B.personid
    order by C.personidselect A.deptname, sum(C.money) from A 
     left join B on A.deptbh = B.deptbh
     left join C on C.personid = B.personid
    group by A.deptname