我现在有一个视图:V_ZJ_YSK(应收款),一个表ZJ_skd(收款单)
他们的字段为:V_ZJ_YSK(MingCheng,ZongShiYang,ShiJian,CZY_Name,CZY_Name)
ZJ_skd(ID,jine,mingcheng,caozuoyuan_id,caozuoshijian,JingShouRen)
我现在要通过ZJ_skd(收款单)一个具体单位付给的总金额减去他所对应的V_ZJ_YSK(应收款)应收款的总金额来得到一个差值.
我用了以下的方法:
(select sum(ZongShiYang) ZongShiYang,MingCheng
from dbo.V_ZJ_YSK
group by MingCheng)
union
(select sum(Jine) Jine,Mingcheng
from ZJ_skd
group By MingCheng)
但是行不通,不能得到相应的差.
希望各位帮忙看一下!!!!
谢谢!!!
他们的字段为:V_ZJ_YSK(MingCheng,ZongShiYang,ShiJian,CZY_Name,CZY_Name)
ZJ_skd(ID,jine,mingcheng,caozuoyuan_id,caozuoshijian,JingShouRen)
我现在要通过ZJ_skd(收款单)一个具体单位付给的总金额减去他所对应的V_ZJ_YSK(应收款)应收款的总金额来得到一个差值.
我用了以下的方法:
(select sum(ZongShiYang) ZongShiYang,MingCheng
from dbo.V_ZJ_YSK
group by MingCheng)
union
(select sum(Jine) Jine,Mingcheng
from ZJ_skd
group By MingCheng)
但是行不通,不能得到相应的差.
希望各位帮忙看一下!!!!
谢谢!!!
select sum(ZongShiYang) ZongShiYang,MingCheng
from dbo.V_ZJ_YSK
group by MingCheng)
union
(select sum(Jine) Jine,Mingcheng
from ZJ_skd
group By MingCheng)select sum(ZongShiYang)-sum(Jine)
from dbo.V_ZJ_YSK a, ZJ-skd b
where a.MingCheng =b.MingCHeng
select sum(ZongShiYang) ZongShiYang,MingCheng
from dbo.V_ZJ_YSK
group by MingCheng) select sum(Jine) Jine,Mingcheng
from ZJ_skd
group By MingCheng 你可以把这两名SQL分开看就明白我的意思,我是要从ZJ_skd表中客户给我的总钱数去减掉V_ZJ_YSK中同一个客户发生的欠款总和,从而得到一个差.你的结果不对!
((select sum(ZongShiYang) as ZongShiYang,MingCheng
from dbo.V_ZJ_YSK
group by MingCheng) union(select sum(0-Jine) as ZongShiYang ,Mingcheng
from ZJ_skd
group By MingCheng ))
group by Mingcheng
应该是你要的要求的