SQL Server Query LEFT JOIN, SUM and GROUP BY and I'm stumped!

前端 未结 4 1227
既然无缘
既然无缘 2021-01-05 00:29

I am beating my brain against this one

I have 3 SQL Server 2005 tables

userawards:

id, awardamount, userid, dateawarded, aw         


        
4条回答
  •  -上瘾入骨i
    2021-01-05 01:04

    SELECT
      ui.FirstName
     ,ui.LastName
     ,at.Title AS Award
     ,SUM(a.AwardAmount) AS AwardAmount
    FROM Awards a
      INNER JOIN UserInfo ui ON ui.UserId = a.UserId
      INNER JOIN AwardTypes at ON at.AwardTypeId = a.AwardTypeId
    GROUP BY ui.FirstName, ui.LastName, at.Title
    ORDER BY ui.LastName, ui.FirstName
    

提交回复
热议问题