大家给看看这个sql语句,我实在看不懂,关键是LEFT OUTER JOIN,谢谢了
SELECT dbo.wuliu_huopin.bianhao AS pinming,dbo.wuliu_huopin.mingcheng AS mingcheng,dbo.wuliu_huopin.sp_xinhao AS sp_xinhao, dbo.wuliu_huopin.lei AS lei,shuliang=case when sum(shuliang) is null then 0 else sum(shuliang) end,dbo.wuliu_huopin.danwei,dbo.wuliu_huopin.xiaoshoujia FROM dbo.wuliu_huopin LEFT OUTER JOIN dbo.wuliu_ruku ON dbo.wuliu_huopin.bianhao = dbo.wuliu_ruku.pinming WHERE (dbo.wuliu_huopin.shangpingbj = 1 and dbo.wuliu_huopin.lei= "&leiid& ") group by bianhao,mingcheng,sp_xinhao,wuliu_huopin.lei,wuliu_huopin.danwei,xiaoshoujia
------解决方案--------------------呵呵,这么写SQL语句的人真的不是一般的笨。
这样写完后自己看都费劲,就别说别人了。。。
给表起个别名就完了,非得整个dbo.wuliu_huopin
这是一个汇总的联合查询。。。
取出wuliu_huopin表中bianhao,mingcheng,sp_xinhao,lei,danwei,xiaoshoujia 这几列并对
shuliang进行求和。
表wuliu_huopin和表wuliu_ruku左连接条件是wuliu_huopin.bianhao =dbo.wuliu_ruku.pinming和WHERE (dbo.wuliu_huopin.shangpingbj = 1 and dbo.wuliu_huopin.lei= "&leiid& ")
后面的group by 是分组滤重的。。。