Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
11.4. Sorting
So far, we’ve only looked at rows of data in the order of the query is
returning to us. What if we want to see the rows in a certain sorting
order? We use the ORDER BY
command to sort them by some other
criteria.
For example, to see the bike trips in the order of the duration in
seconds:
Well, it turns out by default the sorting order is ascending. To
sort the rows in descending order, add the keyword DESC
.
Of course, we can mix WHERE
and ORDER BY
, to get only the bike
trips from Member type of Casual in the order of the duration.
11.4.1. Practice Exercises
select bike_number, duration from trip_data order by duration desc limit 1;
select start_station, duration from trip_data where start_station = end_station order by duration desc limit 1;
Get the start and end station IDs for bike trips that are longer 60 minutes or longer, in the order of largest number of seconds first and display the top 40 results.
On which bike was longest bike ride? How many seconds long was that ride?
What is the starting station and duration of the longest ride starting and ending at the same station?
You have attempted
of
activities on this page