SELECT [UserID],[Name],[RegisterDate]
,((select sum([Score]) as sum1 from [UserInfo] where [UserID]=t.[UserID])
+(select sum([Price]*[Count]) as sum2 FROM [Property] where [UserID]=t.[UserID])
+(select sum(PPrice*PCount) as sum3 FROM [Present] where [UserID] =t.[UserID]))
AS [3句的和]
FROM [Acinfo] t (NOLOCK)
WHERE t.[UserID]
SELECT [UserID],[Name],[RegisterDate]
,((select sum([Score]) as sum1 from [UserInfo] where [UserID]=t.[UserID])
+(select sum([Price]*[Count]) as sum2 FROM [Property] where [UserID]=t.[UserID])
+(select sum(PPrice*PCount) as sum3 FROM [Present] where [UserID] =t.[UserID]))
AS [3句的和]
FROM [Acinfo] t (NOLOCK)
WHERE t.[UserID]=2
SELECT [UserID],[Name],[RegisterDate],sum([Score]) as sum1
, sum([Price]*[Count]) as sum2
,sum(PPrice*PCount) as sum3
FROM [Acinfo] a
JOIN [UserInfo] u ON a.UserID = u.UserID
JOIN Property p ON a.UserID = p.UserID
JOIN [Present] t ON a.UserID = t.UserID
GROUP BY [UserID],[Name],[RegisterDate]
--用isnull
SELECT [UserID],[Name],[RegisterDate]
,((select isnull(sum([Score]),0) as sum1 from [UserInfo] where [UserID]=t.[UserID])
+(select isnull(sum([Price]*[Count]),0) as sum2 FROM [Property] where [UserID]=t.[UserID])
+(select isnull(sum(PPrice*PCount),0) as sum3 FROM [Present] where [UserID] =t.[UserID]))
AS [3句的和]
FROM [Acinfo] t (NOLOCK)
WHERE t.[UserID]=2