-
Notifications
You must be signed in to change notification settings - Fork 0
/
answers.SQL
102 lines (85 loc) · 1.96 KB
/
answers.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
### Limits
/*
Select columns occurred_at, account_id and channel
from web_events and limit to 15 rows
*/
SELECT occurred_at, account_id, channel
FROM web_events
LIMIT 15
/*
Write a query to return the 10 earliest orders
in the orders table. Include the id, occurred_at,
and total_amt_usd.
*/
SELECT id, occurred_at, total_amt_usd
FROM orders
ORDER BY occurred_at
LIMIT 10
/*
Write a query to return the top 5 orders
in terms of largest total_amt_usd.
Include the id, account_id, and total_amt_usd.
*/
SELECT id, occurred_at, total_amt_usd
FROM orders
ORDER BY total_amt_usd DESC
LIMIT 5
/*
Write a query to return the bottom 20
orders in terms of least total.
Include the id, account_id, and total.
*/
SELECT id, account_id, total
FROM orders
ORDER BY total
LIMIT 20
/*
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.
*/
SELECT *
FROM orders
ORDER BY occurred DESC, total_amt_usd DESC
LIMIT 5
/*
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.
*/
SELECT *
FROM orders
ORDER BY occurred_at, total_amt_usd
LIMIT 10
/*
Pull the first 5 rows
and all columns from the orders
table that have a dollar
amount of gloss_amt_usd greater
than or equal to 1000.
*/
SELECT *
FROM orders
WHERE gloss_amt_usd >= 1000
LIMIT 5;
/*
Pull the first 10 rows
and all columns from the orders
table that have a total_amt_usd
less than 500
*/
SELECT *
FROM orders
WHERE total_amt_usd < 500
LIMIT 10;
/*
Filter the accounts table to include
the company name, website,
and the primary point of contact (primary_poc)
for Exxon Mobil in the accounts table.
*/
SELECT name, website, primary_poc
FROM accounts
WHERE name = 'Exxon Mobil'