Basic Joins¶
Table of Contents¶
- 1378. Replace Employee ID With The Unique Identifier (Easy)
- 1068. Product Sales Analysis I (Easy)
- 1581. Customer Who Visited but Did Not Make Any Transactions (Easy)
- 197. Rising Temperature (Easy)
- 1661. Average Time of Process per Machine (Easy)
- 577. Employee Bonus (Easy)
- 1280. Students and Examinations (Easy)
- 570. Managers with at Least 5 Direct Reports (Medium)
- 1934. Confirmation Rate (Medium)
1378. Replace Employee ID With The Unique Identifier¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: database
1068. Product Sales Analysis I¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: database
1581. Customer Who Visited but Did Not Make Any Transactions¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: database
1581. Customer Who Visited but Did Not Make Any Transactions-- 1. Left Join SELECT v.customer_id, COUNT(v.visit_id) AS count_no_trans FROM visits AS v LEFT JOIN transactions AS t ON v.visit_id = t.visit_id WHERE t.transaction_id IS NULL GROUP BY v.customer_id; -- 2. Subquery SELECT customer_id, COUNT(DISTINCT visit_id) AS count_no_trans FROM visits WHERE visit_id NOT IN ( SELECT visit_id FROM transactions ) GROUP BY customer_id;
197. Rising Temperature¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: database
1661. Average Time of Process per Machine¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: database
1661. Average Time of Process per MachineSELECT a1.machine_id, ROUND(AVG(a2.timestamp - a1.timestamp), 3) AS processing_time -- ROUND(SUM(a2.timestamp - a1.timestamp) / COUNT(*), 3) AS processing_time FROM activity AS a1 INNER JOIN activity AS a2 ON a1.machine_id = a2.machine_id AND a1.process_id = a2.process_id AND a1.timestamp < a2.timestamp GROUP BY a1.machine_id;
577. Employee Bonus¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: database
1280. Students and Examinations¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: database
1280. Students and ExaminationsSELECT st.student_id, st.student_name, su.subject_name, COUNT(ex.student_id) AS attended_exams FROM students AS st CROSS JOIN subjects AS su LEFT JOIN examinations AS ex ON st.student_id = ex.student_id AND su.subject_name = ex.subject_name GROUP BY st.student_id, st.student_name, su.subject_name ORDER BY st.student_id, su.subject_name;
570. Managers with at Least 5 Direct Reports¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: database
1934. Confirmation Rate¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: database