petarkobakov

9. Clients with ZIP Codes (CigarShop Database)

Feb 16th, 2023
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. -- 9. Clients with ZIP Codes
  2.  
  3. SELECT
  4. CONCAT_WS(' ', cl.FirstName, cl.LastName) AS FullName,
  5. a.Country,
  6. a.ZIP,
  7. CONCAT('$',MAX(cg.PriceForSingleCigar)) AS CigarPrice
  8. FROM Addresses AS a
  9. JOIN Clients AS cl
  10. ON a.Id = cl.AddressId
  11. JOIN ClientsCigars AS cc
  12. ON cl.Id = cc.ClientId
  13. JOIN Cigars AS cg
  14. ON cc.CigarId = cg.Id
  15. WHERE ISNUMERIC(ZIP) = 1
  16. GROUP BY CONCAT_WS(' ', cl.FirstName, cl.LastName), a.Country, a.ZIP
  17. ORDER BY FullName
Advertisement
Add Comment
Please, Sign In to add comment