Advertisement
Silviya7

17. Highest Peak and Longest River by Country

May 31st, 2022 (edited)
3,821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.75 KB | None | 0 0
  1. --17
  2.  
  3. SELECT TOP (5) P.CountryName, P.Elevation AS HighestPeakElevation
  4. , p.LENGTH AS LongestRiverLength
  5. FROM
  6. (
  7. SELECT c.CountryName,p.PeakName, p.Elevation ,
  8.  
  9. DENSE_RANK() OVER(partition BY c.CountryName ORDER BY
  10. p.Elevation DESC)
  11. AS Rank,
  12. R.RiverName,R.LENGTH ,
  13.  
  14. DENSE_RANK() OVER(partition BY c.CountryName ORDER BY r.LENGTH DESC)
  15. AS Rankr
  16. FROM Countries c
  17. LEFT JOIN MountainsCountries mc ON C.CountryCode=
  18. mc.CountryCode.
  19. LEFT JOIN Mountains m ON m.id= mc.MountainId
  20. LEFT JOIN  Peaks p ON P.MountainId= M.Id
  21. LEFT JOIN CountriesRivers cr ON cr.CountryCode= c.CountryCode
  22. LEFT JOIN Rivers r ON R.Id= CR.RiverId
  23.   ) AS P
  24.   WHERE P.Rank=1 AND P.Rankr=1
  25.   ORDER BY HighestPeakElevation DESC,
  26.   LongestRiverLength DESC,P.CountryName ASC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement