▸_sqlgym

21. Highest and Lowest Earner

MediumCTEsORDER BY + LIMIT inside a CTEUNION ALLfinal ordering

ORDER BY ... LIMIT is meaningful inside a CTE — it picks which row survives. But the order of the final output is only guaranteed by the outer query's ORDER BY. This problem makes both ideas concrete.

Task: return two rows — the highest earner and the lowest earner — each labelled. Columns: kind ('highest' or 'lowest'), name, salary. Order the final result by salary descending.

Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…

This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases 5test cases in all. A sloppy query that only fits the example won't pass.

SQL
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.