18. Order by Best Value
EasyOrderingcomputed sort keyCASTalias in ORDER BY
You can order by an expression — even one you've aliased in the
SELECT.
Task: for each book compute value = pages / price (pages per rupee) and
return title and the rounded value (2 decimals). Order by value
descending so the best-value books come first; break ties by title.
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· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.