Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 791cac3

Browse files
committed
Adding solutions
1 parent 764cd61 commit 791cac3

17 files changed

+103
-0
lines changed

‎dump_file/leetcodedb.sql

5 Bytes
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SELECT country_name,
2+
CASE WHEN AVG(weather_state) <= 15 THEN 'Cold'
3+
WHEN AVG(weather_state) >= 25 THEN 'Hot'
4+
ELSE 'Warm'
5+
END AS weather_type
6+
FROM weather_1294 w
7+
INNER JOIN countries_1294 c ON w.country_id = c.country_id
8+
WHERE EXTRACT(month FROM day) = 11
9+
GROUP BY country_name;
10+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT employee_id,
2+
COUNT(employee_id) OVER (PARTITION BY team_id) AS team_size
3+
FROM employee_1303
4+
ORDER BY employee_id;

‎easy/1322. Ads Performance (Easy).sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SELECT ad_id,
2+
COALESCE(ROUND(AVG(
3+
CASE WHEN action = 'Clicked' THEN 1
4+
WHEN action = 'Viewed' THEN 0
5+
ELSE NULL
6+
END)*100,2),0.00) AS ctr
7+
FROM ads_1322
8+
GROUP BY ad_id
9+
ORDER BY ctr DESC;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SELECT p.product_name,SUM(o.unit)
2+
FROM orders_1327 o
3+
INNER JOIN products_1327 p ON o.product_id = p.product_id
4+
WHERE DATE_TRUNC('MONTH',o.order_date)::DATE = '2020年02月01日'
5+
GROUP BY p.product_name
6+
HAVING SUM(o.unit) >= 100;
7+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT s.id,s.name
2+
FROM students_1350 s
3+
LEFT JOIN departments_1350 d ON s.department_id = d.id
4+
WHERE d.id IS NULL;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT eu.unique_id,e.name
2+
FROM employee_1378 e
3+
LEFT JOIN employee_uni_1378 eu ON e.id = eu.id
4+
ORDER BY e.name;

‎easy/1407. Top Travellers (Easy).sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT u.name,COALESCE(SUM(r.distance),0) AS travelled_distance
2+
FROM users_1407 u
3+
LEFT JOIN rides_1407 r ON u.id = r.user_id
4+
GROUP BY u.name
5+
ORDER BY travelled_distance DESC,u.name;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
WITH bins AS (
2+
SELECT '[0-5>' AS bin, 0 AS min_duration, 5*60 AS max_duration
3+
UNION ALL
4+
SELECT '[5-10>' AS bin, 5*60 AS min_duration, 10*60 AS max_duration
5+
UNION ALL
6+
SELECT '[10-15>' AS bin, 10*60 AS min_duration, 15*60 AS max_duration
7+
UNION ALL
8+
SELECT '15 or more' AS bin, 15*60 as min_duration, 2147483647 AS max_duration
9+
)
10+
SELECT b.bin, COUNT(s.session_id) AS total
11+
FROM bins b
12+
LEFT JOIN sessions_1435 s
13+
ON s.duration >= min_duration
14+
AND s.duration < max_duration
15+
GROUP BY b.bin;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT sell_date,COUNT(DISTINCT product) AS num_sold,STRING_AGG(DISTINCT product,',' ORDER BY product) AS products
2+
FROM activities_1484
3+
GROUP BY sell_date
4+
ORDER BY sell_date;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /