日期:2014-05-18 浏览次数:20422 次
select a.UserId,@MoneyAvailable = SUM(a.Vstock_TotalMoney - (b.BuyPrice * b.BuyVol + b.BuyTax + b.BuyFee) ) from dbo.aspnet_Users a inner join dbo.aspnet_Vstock_BuyOrder b on a.UserId = @UserId and b.UserId = a.UserId GRoup by a.UserId
------解决方案--------------------
高手们出马 你的问题会立即解决的 过来学习了
------解决方案--------------------
select @MoneyAvailable=(
a.Vstock_TotalMoney-
(select SUM(b.BuyPrice * b.BuyVol) from dbo.aspnet_Vstock_BuyOrder b where b.UserId = a.UserId)-
(select SUM(b.BuyTax) from dbo.aspnet_Vstock_BuyOrder b where b.UserId = a.UserId)-
(select SUM(b.BuyFee) from dbo.aspnet_Vstock_BuyOrder b where b.UserId = a.UserId)
)
from dbo.aspnet_Users a
where a.UserId = @UserId
你这个要用子查询来做。
------解决方案--------------------
select @MoneyAvailable=Vstock_TotalMoney
from dbo.aspnet_Users where UserId = @UserId
select @MoneyAvailable = @MoneyAvailable - SUM(b.BuyPrice * b.BuyVol) - SUM(b.BuyTax) - SUM(b.BuyFee)
from dbo.aspnet_Users a
inner join dbo.aspnet_Vstock_BuyOrder b
on a.UserId = @UserId and b.UserId = a.UserId