Advertisement
dragonbs

Highest Peak and Longest River by Country

Sep 28th, 2023
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.53 KB | None | 0 0
  1. SELECT TOP(5)
  2.     c.[CountryName],
  3.     MAX(p.[Elevation]) AS [HighestPeakElevation],
  4.     MAX(r.[Length]) AS [LongestRiverLength]
  5. FROM [Countries] c
  6. LEFT JOIN [MountainsCountries] mc ON c.[CountryCode] = mc.[CountryCode]
  7. LEFT JOIN [Mountains] m ON mc.[MountainId] = m.Id
  8. LEFT JOIN [Peaks] p ON m.[Id] = p.[MountainId]
  9. LEFT JOIN [CountriesRivers] cr ON c.[CountryCode] = cr.[CountryCode]
  10. LEFT JOIN [Rivers] r ON cr.[RiverId] = r.Id
  11. GROUP BY c.[CountryName]
  12. ORDER BY [HighestPeakElevation] DESC, [LongestRiverLength] DESC, c.[CountryName]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement