-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoice.sql
51 lines (32 loc) · 1.02 KB
/
invoice.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
-- 1: Count how many orders were made from the USA.
SELECT COUNT(*) FROM invoice
WHERE billing_country = 'USA';
-- 2: Find the largest order total amount.
SELECT total FROM invoice
ORDER BY total DESC
LIMIT 1;
-- 3: Find the smallest order total amount.
SELECT total FROM invoice
ORDER BY total ASC
LIMIT 1;
-- 4: Find all orders bigger than $5.
SELECT * FROM invoice
WHERE total > 5;
-- 5: Count how many orders were smaller than $5.
SELECT COUNT(*) FROM invoice
WHERE total < 5;
-- 6: Count how many orders were in CA, TX, or AZ (use IN).
SELECT billing_state, COUNT(*) FROM invoice
WHERE billing_state IN ('CA', 'TX', 'AZ')
GROUP BY billing_state;
-- 7: Get the average total of the orders.
SELECT AVG(total) FROM invoice;
-- 8: Get the total sum of the orders.
SELECT SUM(total) FROM invoice;
-- 9: Update the invoice with an invoice_id of 5 to have a total order amount of 24.
UPDATE invoice
SET total = 24
WHERE invoice_id = 5;
-- 10: Delete the invoice with an invoice_id of 1.
DELETE FROM invoice
WHERE invoice_id = 1;