Skip to content

Commit d40cc4e

Browse files
authored
feat: add sql solutions to lc problems: No.1113,1126 (#1200)
* No.1113.Reported Posts * No.1126.Active Businesses
1 parent eebad8a commit d40cc4e

File tree

6 files changed

+53
-39
lines changed

6 files changed

+53
-39
lines changed

Diff for: solution/1100-1199/1113.Reported Posts/README.md

+4-11
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,10 @@ Result table:
6767

6868
```sql
6969
# 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;
8174
```
8275

8376
<!-- tabs:end -->

Diff for: solution/1100-1199/1113.Reported Posts/README_EN.md

+4-11
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,10 @@ Actions table:
7171

7272
```sql
7373
# 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;
8578
```
8679

8780
<!-- tabs:end -->

Diff for: solution/1100-1199/1113.Reported Posts/Solution.sql

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# 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
53
FROM Actions
64
WHERE action_date = '2019-07-04' AND action = 'report'
7-
GROUP BY extra;
5+
GROUP BY 1;

Diff for: solution/1100-1199/1126.Active Businesses/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,20 @@ GROUP BY business_id
7777
HAVING COUNT(1) > 1;
7878
```
7979

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+
8096
<!-- tabs:end -->

Diff for: solution/1100-1199/1126.Active Businesses/README_EN.md

+16
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,20 @@ GROUP BY business_id
8585
HAVING COUNT(1) > 1;
8686
```
8787

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+
88104
<!-- tabs:end -->
+11-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# Write your MySQL query statement below
2-
SELECT business_id
3-
FROM
4-
EVENTS AS t1
5-
JOIN (
2+
WITH
3+
T AS (
64
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;

0 commit comments

Comments
 (0)