-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathqueries.sql
95 lines (79 loc) · 2.1 KB
/
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
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
-- get total number of vine reviews
SELECT COUNT(review_id)
FROM vine_table
WHERE vine = 'Y'
-- output = 1747
-- get total number of non-vine reviews
SELECT COUNT(review_id)
FROM vine_table
WHERE vine = 'N'
-- output = 958932
-- get number of 5 star ratings for vine reviews
SELECT COUNT(review_id)
FROM vine_table
WHERE vine = 'Y' AND star_rating = 5
-- output = 605
-- get number of 5 star ratings for non-vine reviews
SELECT COUNT(review_id)
FROM vine_table
WHERE vine = 'N' AND star_rating = 5
-- output = 570888
-- get average ratings for vine reviews
SELECT AVG(star_rating)
FROM vine_table
WHERE vine = 'Y'
-- output = 4.0
-- get average ratings for non-vine reviews
SELECT AVG(star_rating)
FROM vine_table
WHERE vine = 'N'
-- output = 4.1
-- get average number of helpful votes for vine reviews
SELECT AVG(helpful_votes)
FROM vine_table
WHERE vine = 'Y'
-- output = 2.86
-- get average number of helpful votes for non- vine reviews
SELECT AVG(helpful_votes)
FROM vine_table
WHERE vine = 'N'
-- output = 1.19
-- =======================================================
-- CHECK DATA IF FILTERED BY HELPFUL VOTES GREATER THAN 5
-- =======================================================
-- total number of reviews
SELECT COUNT(review_id)
FROM vine_table
WHERE vine = 'Y' AND helpful_votes > 5
-- output = 188
SELECT COUNT(review_id)
FROM vine_table
WHERE vine = 'N' AND helpful_votes > 5
-- output = 41045
-- number of 5 star ratings
SELECT COUNT(review_id)
FROM vine_table
WHERE vine = 'Y' AND helpful_votes > 5 AND star_rating = 5
-- output = 71
SELECT COUNT(review_id)
FROM vine_table
WHERE vine = 'N' AND helpful_votes > 5 AND star_rating = 5
-- output = 21815
-- average ratings
SELECT AVG(star_rating)
FROM vine_table
WHERE vine = 'Y' AND helpful_votes > 5
-- output = 4.0
SELECT AVG(star_rating)
FROM vine_table
WHERE vine = 'N' AND helpful_votes > 5
-- output = 3.9
-- average number of helpful votes
SELECT AVG(helpful_votes)
FROM vine_table
WHERE vine = 'Y' AND helpful_votes > 5
-- output = 17.56
SELECT AVG(helpful_votes)
FROM vine_table
WHERE vine = 'N' AND helpful_votes > 5
-- output = 15.92