-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-tables.sql
67 lines (50 loc) · 1.71 KB
/
create-tables.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
-- create table A
CREATE TABLE IF NOT EXISTS table_a (
campaign_name STRING,
campaign_id INTEGER
);
-- delete any existing data in table A
DELETE FROM table_a;
-- insert new values into table A
INSERT INTO table_a (campaign_name, campaign_id)
VALUES ('Instacash Promo 1', 112233), ('Instacash Promo 2', 112244), ('RoarMoney Balance 5', 112259);
-- create table B
CREATE TABLE IF NOT EXISTS table_b (
campaign_id INTEGER,
delivery_date DATE,
user_id STRING
);
-- delete any existing data in table B
DELETE FROM table_b;
-- insert new values into table B
INSERT INTO table_b (campaign_id, delivery_date, user_id)
VALUES (112233, '2021-01-01', 'a'), (112233, '2021-01-01', 'b'), (112233, '2021-01-01', 'c'),
(112244, '2021-01-05', 'd'), (112244, '2021-01-05', 'e');
-- create table C
CREATE TABLE IF NOT EXISTS table_c (
campaign_id INTEGER,
open_date DATE,
user_id STRING
);
-- delete any existing data in table C
DELETE FROM table_c;
-- insert new values into table C
INSERT INTO table_c (campaign_id, open_date, user_id)
VALUES (112233, '2021-01-03', 'a'), (112233, '2021-01-05', 'b'), (112244, '2021-01-07', 'd'),
(112244, '2021-01-10', 'e');
-- create table D
CREATE TABLE IF NOT EXISTS table_d (
campaign_id INTEGER,
click_date DATE,
user_id STRING
);
-- delete any existing data in table D
DELETE FROM table_d;
-- insert new values into table D
INSERT INTO table_d (campaign_id, click_date, user_id)
VALUES (112233, '2021-01-03', 'a'), (112244, '2021-01-11', 'e');
-- View the tables
SELECT campaign_name, campaign_id FROM table_a;
SELECT campaign_id, delivery_date, user_id FROM table_b;
SELECT campaign_id, open_date, user_id FROM table_c;
SELECT campaign_id, click_date, user_id FROM table_d;