elena1234

Continents and Currencies - with CTE ( T-SQL )

Dec 31st, 2021 (edited)
817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.49 KB | None | 0 0
  1. -- 15.Continents and Currencies From Subqueries and Joins
  2. WITH CTE AS
  3. (
  4.   SELECT Countries.ContinentCode, Countries.CurrencyCode, COUNT(Countries.CurrencyCode) AS CurrencyUsage,
  5.   DENSE_RANK() OVER(PARTITION BY Countries.ContinentCode ORDER BY COUNT(Countries.CurrencyCode) DESC) AS RN
  6.   FROM Countries
  7.   GROUP BY Countries.CurrencyCode, Countries.ContinentCode
  8. )
  9. SELECT ContinentCode, CurrencyCode, CurrencyUsage
  10. FROM CTE
  11. WHERE RN = 1 AND CTE.CurrencyUsage != 1
  12. ORDER BY CTE.ContinentCode
Add Comment
Please, Sign In to add comment