Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A fair lists its rides and the length of each ride in minutes in a table Rides.
Ride Minutes
Wave 6
Loop 9
Drop 3
Spin 7
Glide 12Write down the output of this script. How many minutes does the first ride in the output last?
SELECT Ride, Minutes
FROM Rides
ORDER BY Minutes DESC;ORDER BY field ASC sorts the output smallest first (A to Z, earliest date first); DESC sorts largest first. The clauses come in the order SELECT, FROM, WHERE, ORDER BY. Keep the records that pass, sort them, then show the selected fields.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. Sort all five lengths, largest first. , , , and minutes.
Step 2. The output.
SELECT Ride, Minutes
FROM Rides
ORDER BY Minutes DESC;The output:
Ride Minutes
Glide 12
Loop 9
Spin 7
Wave 6
Drop 3Answer: the Glide comes first, at minutes. The Drop, at minutes, comes last.
Log in to join the discussion.
Loading…