-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_order_reservable.sql
38 lines (36 loc) · 1.08 KB
/
06_order_reservable.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Goal: learn how ORDER BY your results
Which campgroud has the most reservable campsites?
- Notice we use LIMIT 1 to only return the first result
*/
SELECT
name, campsites_reservable
FROM
campground
ORDER BY
campsites_reservable DESC
LIMIT 1;
-- result
-- +-----------------------+----------------------+
-- | name | campsites_reservable |
-- +-----------------------+----------------------+
-- | Bridge Bay Campground | 432 |
-- +-----------------------+----------------------+
/*
From campgrounds that allow reservations, which one has the fewest reservable campsites?
- Notice that we use WHERE to filter campgrounds with 0 reservable campsites
*/
SELECT
name, campsites_reservable
FROM
campground
WHERE campsites_reservable > 0
ORDER BY
campsites_reservable ASC
LIMIT 1;
-- result
-- +----------------------+----------------------+
-- | name | campsites_reservable |
-- +----------------------+----------------------+
-- | 277 North Campground | 1 |
-- +----------------------+----------------------+