Advertisement
Guest User

Problem 23 - User in Games with Their Items

a guest
Oct 13th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.43 KB | None | 0 0
  1. SELECT u.Username, g.Name AS [Game], COUNT(i.Id) AS [Items COUNT], SUM(i.Price) AS [Items Price]
  2.   FROM Games AS g
  3.   JOIN UserGameItems AS ugi
  4.     ON ugi.UserGameId = g.Id
  5.   JOIN Items AS i
  6.     ON i.Id = ugi.ItemId
  7.   JOIN UsersGames AS ug
  8.     ON ug.GameId = ugi.UserGameId
  9.   JOIN Users AS u
  10.     ON u.Id = ug.UserId
  11.  GROUP BY u.Username, g.Name
  12. HAVING COUNT(i.Id) >= 10
  13.  ORDER BY [Items COUNT] DESC, [Items Price] DESC, Username
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement