日期:2014-05-18  浏览次数:20873 次

请问一个结合查询怎么写?
a是主表,b是重表记录明细, a与b的djh对应. a一对多.

select djh,xm,nj from a

select djh ,sum(fs) fs from b group by djh


请问如何结合上面2条语句得到汇总结果

djh xm nj fs
001 张三 一年 80
002 李四 一年 85
.
.
.


------解决方案--------------------
SQL code

select a.djh,a.xm,a.nj,sum(b.fs) fs
from a join b on a.djh = b.djh
group by a.djh,a.xm,a.nj

------解决方案--------------------
select a.djh,a.xm,a.nj,c.fs from a ,(select djh ,sum(fs) fs from b group by djh) c where a.djh=c.djh