-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-novice.sql
More file actions
42 lines (35 loc) · 897 Bytes
/
Copy path01-novice.sql
File metadata and controls
42 lines (35 loc) · 897 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-- Lesson 01: Novice SQL
-- Goal: learn SELECT, WHERE, ORDER BY, LIMIT, and basic aggregates.
-- 1. Inspect the table.
SELECT *
FROM superstore
LIMIT 10;
-- 2. Select only the columns you need.
SELECT order_id, order_date, customer_name, sales, profit
FROM superstore
LIMIT 10;
-- 3. Filter rows.
SELECT order_id, customer_name, region, sales
FROM superstore
WHERE region = 'West';
-- 4. Sort rows.
SELECT product_name, sales, profit
FROM superstore
ORDER BY sales DESC
LIMIT 10;
-- 5. Aggregate data.
SELECT
COUNT(*) AS total_rows,
SUM(sales) AS total_sales,
SUM(profit) AS total_profit,
AVG(sales) AS avg_sales
FROM superstore;
-- 6. Explore the date dimension.
SELECT date_actual, day_name, month_name, year_actual
FROM periode
LIMIT 10;
-- 7. Find rows with negative profit.
SELECT order_id, product_name, sales, profit
FROM superstore
WHERE profit < 0
ORDER BY profit;