select UserSerialNumber, FirstName, LastName, SUM(SalesAmount) from (
select a.UserSerialNumber, b.FirstName, b.LastName, a.SalesAmount
from Sales a
inner join BaseUser b
on a.UserSerialNumber = b.UserSerialNumber
)
group by UserSerialNumber, FirstName, LastName
select a.UserSerialNumber,b.FirstName,b.LastName,a.Amount1 from(select UserSerialNumber,SUM(SalesAmount) as Amount1 from sales group by UserSerialNumber) aleft join BaseUser b on a.UserSerialNumber=b.UserSerialNumber
declare @BaseUser table(UserSerialNumber nvarchar(20),FirstName nvarchar(50),LastName nvarchar(50),SaleAmount numeric(18,2))
insert into @BaseUser
select UserSerialNumber,FirstName, LastName,null
select BaseUser
update A
set SaleAmount = sum()
from @BaseUser A inner join Sales B on A.UserSerialNumber=B.UserSerialNumber
select * from @BaseUser
select t.userSerialNumber, t.fisrtName, t.lastName, sum(t1.account) as acount
from baseuser t left join sales on t.userSerialNumber = t1.userSerialNumber group by t.userSerialNumber,t. fisrtName,t.lastName
select UserSerialNumber,
FirstName,
LastName,
(select sum(s.SalesAmount) from sales s where s.UserSerialNumber=UserSerialNumber) as totalsales from BaseUser
应该可以,不可以问我