一客户表和3张金额表关联 且要求SUM 关联条件为客户号(khno)
三张金额表 记录了客户对三张类型每次交易的单笔金额 关联条件客户号(KHNO)
现在需要显示成 客户号 A交易总额 B交易总额 C交易总额
0001 2222.33 2323.11 55.00
0002 121.33 0.00 69.00
......
由于是新人自己写了这段测试不行。希望指教
SELECT b.BK_KHNO,b.BK_NAME,badsum.BAD_YUE,asssum.ASS_YUE,lawsum.LAW_SSBD
FROM KeHu_B b
LEFT OUTER JOIN (select lb.LAW_KHNO,sum(lb.LAW_SSBD) as sumlaw from LAW_B lb group by lb.LAW_KHNO) lawsum ON b.BK_KHNO =lawsum.LAW_KHNO
LEFT OUTER JOIN (select ass.ASS_KHNO,sum(ass.ASS_YUE) as sumass from BAD_ASSURE ass group by ass.ASS_KHNO) asssum ON b.BK_KHNO
=asssum.ASS_KHNO
LEFT OUTER JOIN (select bd.BAD_KHNO,sum(bd.BAD_YUE) as sumbad from BAD_DK_B bd group by bd.BAD_KHNO) badsum ON b.BK_KHNO
=badsum.BAD_KHNO
ORDER BY b.BK_ID
------解决方案--------------------------------------------------------
贴记录及要求结果出来看看
------解决方案--------------------------------------------------------
有记录才能测试
------解决方案--------------------------------------------------------
呵呵,自己解决更好
------解决方案--------------------------------------------------------
(select bd.BAD_KHNO,sum(bd.BAD_YUE) as sumbad from BAD_DK_B bd group by bd.BAD_KHNO) badsum
你这里已经没有BADSUM.BAD_YUE 了!
应该是 BADSUM.sumbad