Recap - RANK & DENSE_RANK
Part of the Fundamentals section of Coddy's SQL journey — lesson 66 of 72.
Challenge
MediumAvailable tables and columns:
<strong>medals</strong>:<strong>region</strong>,<strong>medal_color</strong>,<strong>medal_count</strong>
Regions receive medals in competitions. Create a report that shows:
- Calculate for each region:
total_medals: The sum of all medals they haverank_by_medals: Create a dense rank based on total_medals in ascending order (regions with fewer medals get better/lower ranks)
- Order the results by:
rank_by_medals(ascending)region(alphabetically)
return:
regiontotal_medalsrank_by_medals
Try it yourself
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns9Multiple tables
Basic Join Part 1Basic Join Part 2Recap - JoinSelf joinRecap - Self JoinUnionSimplify queries, WITH keywordRecap - With QueriesRecap - Real Estate Contractor12Window Functions part 2
RANK & DENSE_RANK FunctionsRecap - RANK & DENSE_RANKNTILE FunctionAggregation FunctionsROWS & RANGE Criterion