Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. SELECT t.CountryName, t.DistributorName
  2. FROM (
  3. SELECT c.Name AS 'CountryName', d.Name AS 'DistributorName', DENSE_RANK() OVER (PARTITION BY c.Name ORDER BY COUNT(i.Id)) AS 'Ranking' FROM Countries AS c
  4. INNER JOIN Distributors AS d
  5. ON d.CountryId = c.Id
  6. INNER JOIN Ingredients AS i
  7. ON i.DistributorId = d.Id
  8. GROUP BY c.Name, d.Name
  9. ) AS t
  10. WHERE t.Ranking = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement