File tree 6 files changed +53
-39
lines changed
6 files changed +53
-39
lines changed Original file line number Diff line number Diff line change @@ -67,17 +67,10 @@ Result table:
67
67
68
68
``` sql
69
69
# Write your MySQL query statement below
70
- SELECT
71
- extra report_reason,
72
- count (
73
- DISTINCT ( post_id )) report_count
74
- FROM
75
- Actions
76
- WHERE
77
- action_date = ' 2019-07-04'
78
- AND action = ' report'
79
- GROUP BY
80
- extra
70
+ SELECT extra AS report_reason, count (DISTINCT post_id) AS report_count
71
+ FROM Actions
72
+ WHERE action_date = ' 2019-07-04' AND action = ' report'
73
+ GROUP BY 1 ;
81
74
```
82
75
83
76
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -71,17 +71,10 @@ Actions table:
71
71
72
72
``` sql
73
73
# Write your MySQL query statement below
74
- SELECT
75
- extra report_reason,
76
- count (
77
- DISTINCT ( post_id )) report_count
78
- FROM
79
- Actions
80
- WHERE
81
- action_date = ' 2019-07-04'
82
- AND action = ' report'
83
- GROUP BY
84
- extra
74
+ SELECT extra AS report_reason, count (DISTINCT post_id) AS report_count
75
+ FROM Actions
76
+ WHERE action_date = ' 2019-07-04' AND action = ' report'
77
+ GROUP BY 1 ;
85
78
```
86
79
87
80
<!-- tabs:end -->
Original file line number Diff line number Diff line change 1
1
# Write your MySQL query statement below
2
- SELECT
3
- extra AS report_reason,
4
- count (DISTINCT post_id) AS report_count
2
+ SELECT extra AS report_reason, count (DISTINCT post_id) AS report_count
5
3
FROM Actions
6
4
WHERE action_date = ' 2019-07-04' AND action = ' report'
7
- GROUP BY extra ;
5
+ GROUP BY 1 ;
Original file line number Diff line number Diff line change @@ -77,4 +77,20 @@ GROUP BY business_id
77
77
HAVING COUNT (1 ) > 1 ;
78
78
```
79
79
80
+ ``` sql
81
+ # Write your MySQL query statement below
82
+ WITH
83
+ T AS (
84
+ SELECT
85
+ business_id,
86
+ occurences > avg (occurences) OVER (PARTITION BY event_type) AS mark
87
+ FROM Events
88
+ )
89
+ SELECT business_id
90
+ FROM T
91
+ WHERE mark = 1
92
+ GROUP BY 1
93
+ HAVING count (1 ) > 1 ;
94
+ ```
95
+
80
96
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -85,4 +85,20 @@ GROUP BY business_id
85
85
HAVING COUNT (1 ) > 1 ;
86
86
```
87
87
88
+ ``` sql
89
+ # Write your MySQL query statement below
90
+ WITH
91
+ T AS (
92
+ SELECT
93
+ business_id,
94
+ occurences > avg (occurences) OVER (PARTITION BY event_type) AS mark
95
+ FROM Events
96
+ )
97
+ SELECT business_id
98
+ FROM T
99
+ WHERE mark = 1
100
+ GROUP BY 1
101
+ HAVING count (1 ) > 1 ;
102
+ ```
103
+
88
104
<!-- tabs:end -->
Original file line number Diff line number Diff line change 1
1
# Write your MySQL query statement below
2
- SELECT business_id
3
- FROM
4
- EVENTS AS t1
5
- JOIN (
2
+ WITH
3
+ T AS (
6
4
SELECT
7
- event_type ,
8
- AVG (occurences) AS occurences
9
- FROM EVENTS
10
- GROUP BY event_type
11
- ) AS t2
12
- ON t1 . event_type = t2 . event_type
13
- WHERE t1 . occurences > t2 . occurences
14
- GROUP BY business_id
15
- HAVING COUNT (1 ) > 1 ;
5
+ business_id ,
6
+ occurences > avg (occurences) OVER (PARTITION BY event_type) AS mark
7
+ FROM Events
8
+ )
9
+ SELECT business_id
10
+ FROM T
11
+ WHERE mark = 1
12
+ GROUP BY 1
13
+ HAVING count (1 ) > 1 ;
You can’t perform that action at this time.
0 commit comments