-
Notifications
You must be signed in to change notification settings - Fork 1
/
precomputedTableInserts.sql~
35 lines (32 loc) · 1.1 KB
/
precomputedTableInserts.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
INSERT INTO ProdStatePrecomp (
SELECT products.id, states.state, SUM(quantity*sales.price) AS sumamt
FROM products
LEFT JOIN sales ON products.id = pid
JOIN users ON users.id = uid
JOIN states ON states.state = users.state
GROUP BY products.id, states.state
);
INSERT INTO UsersCatPrecomp (
SELECT users.id, categories.name, SUM(quantity*sales.price) AS sumamt
FROM users
LEFT JOIN sales ON users.id = uid
JOIN products ON pid = products.id
JOIN categories ON cid = categories.id
GROUP BY users.id, users.state, categories.name
);
INSERT INTO StateCatPrecomp (
SELECT users.state, categories.name, SUM(quantity*sales.price) AS sumamt
FROM users
LEFT JOIN sales ON users.id = uid
JOIN products ON pid = products.id
JOIN categories ON cid = categories.id
GROUP BY users.state, categories.name
);
INSERT INTO UsersCatProdStatePrecomp (
SELECT users.id, products.category, products.id, users.state, SUM(quantity*sales.price) AS sumamt
FROM users
LEFT JOIN sales ON users.id = uid
JOIN products ON pid = products.id
JOIN categories ON cid = categories.id
GROUP BY users.id, products.id, products.category, users.state
);