我需要从两个表中添加 uniqueid 和 WBid。通过下面的输入,我从两个表中都得到了正确的数据,但它只是按行列出,而不是求和。
select distinct COUNT(l.uniqueid), SUM(r.WBid), l.uniqueid, l.firstname, ``l.lastname, l.email, l.phone, l.mobile, l.address, l.city FROM EDW..lookupuser l
INNER JOIN DB..DimBD b on b.userid = l.userId
INNER JOIN DB..FactVP v on v.BidderId = b.bidderid
INNER JOIN DB..FactRD r on r.buyerid = b.bidderid
and r.AuctionDate > '2012-12-31'
GROUP BY l.uniqueid, l.email, l.phone, l.mobile, l.address, l.city, l.firstname, l.lastname
UNION
select distinct COUNT(l.uniqueid), SUM(t.WBid), l.uniqueid, l.firstname, l.lastname, l.email, l.phone, l.mobile, l.address, l.city FROM EDW..lookupuser l
INNER JOIN DB..DimB b on b.userid = l.userId
INNER JOIN DB..FactVP v on v.BidderId = b.bidderid
INNER JOIN DB..FactTA t on t.BidderId = b.bidderid
and t.AuctionDate > '2012-12-31'
GROUP BY l.uniqueid, l.email, l.phone, l.mobile, l.address, l.city, l.firstname, l.lastname
order by l.email asc