-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRDB_O2.sql
More file actions
28 lines (21 loc) · 774 Bytes
/
RDB_O2.sql
File metadata and controls
28 lines (21 loc) · 774 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
28
-- 1. View the order _details table.
SELECT * FROM order_details;
-- 2. What is the date range of the table?
SELECT * FROM order_details
ORDER BY order_date;
SELECT MIN(order_date), MAX(order_date) FROM order_details;
-- 3. How many orders were made within this date range?
SELECT COUNT(DISTINCT order_id) FROM order_details;
-- 4. How many items were ordered within this date range?
SELECT COUNT(*) FROM order_details;
-- 5. Which orders had the greatest number of items?
SELECT order_id, COUNT(item_id) AS num_items
FROM order_details
GROUP BY order_id
ORDER BY num_items DESC;
-- 6. How many orders had more than 12 items?
SELECT COUNT(*) FROM
(SELECT order_id, COUNT(item_id) AS num_items
FROM order_details
GROUP BY order_id
HAVING num_items > 12) AS num_orders;