forked from PrattJena/Instacart_Project_CSCI_620
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbig_data_phase2_queries.sql
58 lines (36 loc) · 1.33 KB
/
big_data_phase2_queries.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
SELECT pd.product_name, COUNT(*) as frequency
FROM "bigDataProject".products as pd,"bigDataProject".order_products as op
where op.product_id = pd.product_id
GROUP BY pd.product_id
ORDER BY frequency DESC
LIMIT 15;
select cd.user_name,count(*) as frequency
from "bigDataProject".client_data as cd,"bigDataProject".order_products as op,"bigDataProject".products as pd,"bigDataProject".orders as ord
where op.product_id=pd.product_id and
ord.order_id=op.order_id and
ord.user_id=cd.user_id
group by cd.user_name
ORDER BY frequency DESC
LIMIT 5;
SELECT pd.aisle_id
FROM "bigDataProject".aisles AS ai, "bigDataProject".products AS pd
where ai.aisle_id=pd.aisle_id
GROUP BY pd.aisle_id
HAVING COUNT(*) = (
SELECT MAX(frequency)
FROM (
select pd.aisle_id,count(*) as frequency
from "bigDataProject".aisles as ai,"bigDataProject".products as pd
where ai.aisle_id=pd.aisle_id
group by pd.aisle_id
) AS freq_table
);
select distinct cd.user_name,cd.user_email
from "bigDataProject".client_data as cd,"bigDataProject".order_products as op,"bigDataProject".orders as od
where cd.user_name like 'Sh%' and
od.user_id=cd.user_id and
op.product_id=4;
select pd.product_name
from "bigDataProject".products as pd,"bigDataProject".departments as d
where d.department like 'snacks'
and pd.department_id=d.department_id