-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_insights.sql
197 lines (159 loc) · 5.04 KB
/
extract_insights.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
use ub_skincare;
select distinct skin_type from user_recommendations;
/* top 5 cleanser dry skin */
WITH temp AS
(select skin_type, count(favorite_cleanser) as count_cleanser_dry_skin, favorite_cleanser
from user_recommendations
where skin_type='dry'
group by favorite_cleanser)
SELECT *
FROM temp
ORDER BY count_cleanser_dry_skin DESC
LIMIT 5;
/* top 5 cleanser oily skin */
WITH temp AS
(select skin_type, count(favorite_cleanser) as count_cleanser_oily_skin, favorite_cleanser
from user_recommendations
where skin_type='oily'
group by favorite_cleanser)
SELECT *
FROM temp
ORDER BY count_cleanser_oily_skin DESC
LIMIT 5;
/* top 5 cleanser sensitive skin */
WITH temp AS
(select skin_type, count(favorite_cleanser) as count_cleanser_Sensitive_skin, favorite_cleanser
from user_recommendations
where skin_type='Sensitive'
group by favorite_cleanser)
SELECT *
FROM temp
ORDER BY count_cleanser_Sensitive_skin DESC
LIMIT 5;
/* top 5 combination oily skin */
WITH temp AS
(select skin_type, count(favorite_cleanser) as count_cleanser_combination_skin, favorite_cleanser
from user_recommendations
where skin_type='Combination'
group by favorite_cleanser)
SELECT *
FROM temp
ORDER BY count_cleanser_combination_skin DESC
LIMIT 5;
/* top 5 favorite_moisturiser dry skin */
WITH temp AS
(select skin_type, count(favorite_moisturiser) as count_moisturiser_dry_skin, favorite_moisturiser
from user_recommendations
where skin_type='dry'
group by favorite_moisturiser)
SELECT *
FROM temp
ORDER BY count_moisturiser_dry_skin DESC
LIMIT 5;
/* top 5 favorite_moisturiser oily skin */
WITH temp AS
(select skin_type, count(favorite_moisturiser) as count_moisturiser_oily_skin, favorite_moisturiser
from user_recommendations
where skin_type='oily'
group by favorite_moisturiser)
SELECT *
FROM temp
ORDER BY count_moisturiser_oily_skin DESC
LIMIT 5;
/* top 5 favorite_moisturiser sensitive skin */
WITH temp AS
(select skin_type, count(favorite_moisturiser) as count_moisturiser_sensitive_skin, favorite_moisturiser
from user_recommendations
where skin_type='Sensitive'
group by favorite_moisturiser)
SELECT *
FROM temp
ORDER BY count_moisturiser_sensitive_skin DESC
LIMIT 5;
/* top 5 favorite_moisturiser combination skin */
WITH temp AS
(select skin_type, count(favorite_moisturiser) as count_moisturiser_Combination_skin, favorite_moisturiser
from user_recommendations
where skin_type='Combination'
group by favorite_moisturiser)
SELECT *
FROM temp
ORDER BY count_moisturiser_Combination_skin DESC
LIMIT 5;
/* top 5 favorite_sunscreen dry skin */
WITH temp AS
(select skin_type, count(favorite_sunscreen) as count_sunscreen_dry_skin, favorite_moisturiser
from user_recommendations
where skin_type='dry'
group by favorite_sunscreen)
SELECT *
FROM temp
ORDER BY count_sunscreen_dry_skin DESC
LIMIT 5;
/* top 5 favorite_sunscreen oily skin */
WITH temp AS
(select skin_type, count(favorite_sunscreen) as count_sunscreen_oily_skin, favorite_moisturiser
from user_recommendations
where skin_type='oily'
group by favorite_sunscreen)
SELECT *
FROM temp
ORDER BY count_sunscreen_oily_skin DESC
LIMIT 5;
/* top 5 favorite_sunscreen sensitive skin */
WITH temp AS
(select skin_type, count(favorite_sunscreen) as count_sunscreen_sens_skin, favorite_moisturiser
from user_recommendations
where skin_type='Sensitive'
group by favorite_sunscreen)
SELECT *
FROM temp
ORDER BY count_sunscreen_sens_skin DESC
LIMIT 5;
/* top 5 favorite_sunscreen combination skin */
WITH temp AS
(select skin_type, count(favorite_sunscreen) as count_sunscreen_combination_skin, favorite_moisturiser
from user_recommendations
where skin_type='Combination'
group by favorite_sunscreen)
SELECT *
FROM temp
ORDER BY count_sunscreen_combination_skin DESC
LIMIT 5;
/* top 5 favorite_sunscreen combination skin */
WITH temp AS
(select skin_type, count(favorite_sunscreen) as count_sunscreen_combination_skin, favorite_moisturiser
from user_recommendations
where skin_type='Combination'
group by favorite_sunscreen)
SELECT *
FROM temp
ORDER BY count_sunscreen_combination_skin DESC
LIMIT 5;
/* count number of people for different skin_type */
select skin_type, count(age) as people_count
from user_recommendations
group by skin_type;
/* count number of people in different age groups */
select ur.age_range, count(*) as people_count
from (select age,
case when age>=12 and age<=18 then '12-18'
when age>=19 and age<=25 then '19-25'
when age>=26 and age<=34 then '26-34'
when age>=35 and age<=345 then '35-45'
when age>=46 and age<55 then '46-55'
else '55+' end as `age_range`
from user_recommendations) ur
group by ur.`age_range`;
/* count number of people in each age group*/
select ur.age_range, count(*) as people_count
from (select age,
case when age>=12 and age<=18 then '12-18'
when age>=19 and age<=25 then '19-25'
when age>=26 and age<=34 then '26-34'
when age>=35 and age<=345 then '35-45'
when age>=46 and age<55 then '46-55'
else '55+' end as `age_range`
from user_recommendations) ur
group by ur.`age_range`;
/*select * from user_recommendations;*/