8000 Update README.md · Learner457/sql-50-leetcode@4139ffd · GitHub
[go: up one dir, main page]

Skip to content

Commit 4139ffd

Browse files
committed
Update README.md
1 parent 0e79b7d commit 4139ffd

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,59 @@ FROM (
252252
WHERE temp.od = 1
253253
```
254254

255-
<!-- [550. Game Play Analysis IV](https://leetcode.com/problems/game-play-analysis-iv/)
255+
[550. Game Play Analysis IV](https://leetcode.com/problems/game-play-analysis-iv/)
256256
```sql
257+
WITH login_date AS (SELECT player_id, MIN(event_date) AS first_login
258+
FROM Activity
259+
GROUP BY player_id),
257260

258-
``` -->
261+
recent_login AS (
262+
SELECT *, DATE_ADD(first_login, INTERVAL 1 DAY) AS next_day
263+
FROM login_date)
264+
265+
SELECT ROUND((SELECT COUNT(DISTINCT(player_id))
266+
FROM Activity
267+
WHERE (player_id, event_date) IN
268+
(SELECT player_id, next_day FROM recent_login)) / (SELECT COUNT(DISTINCT player_id) FROM Activity), 2) AS fraction
269+
```
270+
[2356. Number of Unique Subjects Taught by Each Teacher](https://leetcode.com/problems/number-of-unique-subjects-taught-by-each-teacher)
271+
```sql
272+
SELECT teacher_id, COUNT(DISTINCT subject_id) cnt
273+
FROM Teacher
274+
GROUP BY teacher_id
275+
```
276+
277+
[1141. User Activity for the Past 30 Days I](https://leetcode.com/problems/user-activity-for-the-past-30-days-i/)
278+
```sql
279+
SELECT activity_date as day, COUNT(DISTINCT user_id) AS active_users
280+
FROM Activity
281+
WHERE activity_date BETWEEN DATE_SUB('2019-07-27', INTERVAL 29 DAY) AND '2019-07-27'
282+
GROUP BY activity_date
283+
```
284+
285+
[1070. Product Sales Analysis III
286+
](https://leetcode.com/problems/product-sales-analysis-iii/)
287+
```sql
288+
SELECT s.product_id, s.year AS first_year, s.quantity, s.price
289+
FROM Sales s
290+
JOIN (
291+
SELECT product_id, MIN(year) AS year
292+
FROM sales
293+
GROUP BY product_id
294+
) p
295+
ON s.product_id = p.product_id
296+
AND s.year = p.year
297+
298+
-- OR
299+
WITH first_year_sales AS (
300+
SELECT s.product_id, MIN(s.year) as first_year
301+
FROM Sales s
302+
INNER JOIN Product p
303+
ON s.product_id = p.product_id
304+
GROUP BY s.product_id)
305+
SELECT f.product_id, f.first_year, s.quantity, s.price
306+
FROM first_year_sales f
307+
JOIN Sales s
308+
ON f.product_id = s.product_id
309+
AND f.first_year = s.year
310+
```

0 commit comments

Comments
 (0)
0