-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLesson3.sql
More file actions
27 lines (23 loc) · 973 Bytes
/
Copy pathLesson3.sql
File metadata and controls
27 lines (23 loc) · 973 Bytes
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
### ORDER BY Part II
/*
1. Write a query that returns the top 5 rows from orders ordered according
to newest to oldest, but with the largest total_amt_usd for each date
listed first for each date. You will notice each of these dates shows up
as unique because of the time element. When you learn about truncating
dates in a later lesson, you will better be able to tackle this question
on a day, month, or yearly basis.
2. Write a query that returns the top 10 rows from orders ordered according
to oldest to newest, but with the smallest total_amt_usd for each date
listed first for each date. You will notice each of these dates shows up
as unique because of the time element. When you learn about truncating
dates in a later lesson, you will better be able to tackle this question
on a day, month, or yearly basis.
*/
SELECT *
FROM orders
ORDER BY occurred_at DESC, total_amt_usd DESC
LIMIT 5;
SELECT *
FROM orders
ORDER BY occurred_at, total_amt_usd
LIMIT 10;