-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunion.sql
More file actions
35 lines (35 loc) · 673 Bytes
/
union.sql
File metadata and controls
35 lines (35 loc) · 673 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
SELECT order_id,
order_date,
'Active' AS status
FROM orders
WHERE order_date >= '2019-01-01'
UNION
SELECT order_id,
order_date,
'Archived' AS status
FROM orders
WHERE order_date < '2019-01-01' -- points<2000 'bronze'
-- points >=2000 AND points<3000 'silver'
-- points >3000 'gold'
SELECT customer_id,
first_name,
points,
'Bronze' AS type
FROM customers
WHERE points < 2000
UNION
SELECT customer_id,
first_name,
points,
'Silver' AS type
FROM customers
WHERE points >= 2000
AND points < 3000
UNION
SELECT customer_id,
first_name,
points,
'Gold' AS type
FROM customers
WHERE points > 3000
ORDER BY first_name