dragonbs

Continents and Currencies

Sep 28th, 2023
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.39 KB | None | 0 0
  1. SELECT rc.[ContinentCode], rc.[CurrencyCode], rc.[CurrencyUsage]
  2. FROM (
  3.     SELECT c.[ContinentCode],
  4.            c.[CurrencyCode],
  5.            COUNT(c.[CurrencyCode]) AS [CurrencyUsage],
  6.            DENSE_RANK() OVER (PARTITION BY c.[ContinentCode] ORDER BY COUNT(c.[CurrencyCode]) DESC) AS [Rank]
  7.     FROM [Countries] c
  8.     GROUP BY c.[ContinentCode], c.[CurrencyCode]) rc
  9. WHERE rc.[Rank] = 1 AND rc.[CurrencyUsage] > 1
Add Comment
Please, Sign In to add comment