File size: 1,152 Bytes
1fb4e2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Task: 045

**Database:** github_repos  

## Question
What is the highest number of issues opened by a single repository (identified by repo ID) in Q3? Use the YEAR_* tables.


## Gold Query

```sql
WITH issue_counts_2022 AS (
SELECT json_extract(repo, '$.id') AS repo_id,
COUNT(DISTINCT json_extract(payload, '$.issue.id')) AS issues_opened
FROM YEAR_2022
WHERE type = 'IssuesEvent'
AND json_extract(payload, '$.action') = 'opened'
AND strftime('%m', created_at / 1000000, 'unixepoch') IN ('07', '08', '09')
GROUP BY repo_id
),
issue_counts_2023 AS (
SELECT json_extract(repo, '$.id') AS repo_id,
COUNT(DISTINCT json_extract(payload, '$.issue.id')) AS issues_opened
FROM YEAR_2023
WHERE type = 'IssuesEvent'
AND json_extract(payload, '$.action') = 'opened'
AND strftime('%m', created_at / 1000000, 'unixepoch') IN ('07', '08', '09')
GROUP BY repo_id
),
max_counts AS (
SELECT MAX(issues_opened) AS max_value FROM issue_counts_2022
UNION ALL
SELECT MAX(issues_opened) AS max_value FROM issue_counts_2023
)
SELECT MAX(max_value) AS overall_max
FROM max_counts;
```

**Execution Result:**

|   overall_max |
|---------------|
|            67 |

*1 rows*