declare @money as money declare @consume as money declare @JY as money select @money =金钱 from 表A where 姓名 ='张某 ' select @consume =sum(扣钱) from 表B where 姓名 ='张某 ' SELECT @JY =@money -@consume
to mgsray(我是新新新新,新来的吧) 没有错,不过得出来的不是我想要的 李某 170 张某 80 还有陈某的哪里去了???
select a.姓名,sum(金钱) from (select 姓名, 金钱 from 表A union all select 姓名,0-扣钱 from 表A )b group by 姓名
btw:以後不許在這裡討論技術問題,這裡是非技術版。 2f:小改一下, select a.姓名,a.金钱-isnull(b.sumkq,0) from a,(select 姓名, sum(扣钱) as sumkq from b group by 姓名)b where a.姓名 *= b.姓名
服务器: 消息 156,级别 15,状态 1,过程 TrueLeaveDate,行 25
在关键字 'select' 附近有语法错误。
declare @consume as money
declare @JY as money
select @money =金钱 from 表A where 姓名 ='张某 '
select @consume =sum(扣钱) from 表B where 姓名 ='张某 '
SELECT @JY =@money -@consume
李某 170
张某 80 还有陈某的哪里去了???
from
(select 姓名, 金钱 from
表A
union all
select 姓名,0-扣钱 from
表A )b
group by 姓名
2f:小改一下,
select a.姓名,a.金钱-isnull(b.sumkq,0) from a,(select 姓名, sum(扣钱) as sumkq from b group by 姓名)b
where a.姓名 *= b.姓名