Basic SQL Exercise Correction
Basic SQL Exercise Correction
Join at
slido.com
#2745 106
October 13, 2024 IT3292E - DATABASE
CREATE RELATION
SELECT pp.patient_id,
pp.name,
COUNT(a.appointment_id) AS appointment_count
FROM Patient pp
JOIN Appointment a ON pp.patient_id = a.patient_id
GROUP BY pp.patient_id, pp.name;
October 13, 2024 IT3292E - DATABASE 7
Underline attributes are primary keys; italic attributes are foreign keys
October 13, 2024 IT3292E - DATABASE 8
SELECT w.project_id,
COUNT(w.employee_id) AS numberOfEmp, p.name
FROM workin w
JOIN project AS p
ON w.project_id = p.project_id
GROUP BY w.project_id;
October 13, 2024 IT3292E - DATABASE 9
A SELECT *
FROM student
WHERE YEAR(date_of_birth) < CURDATE() - 25;
B SELECT *
FROM student
WHERE date_part('year',age(date_of_birth)) < 25;
October 13, 2024 IT3292E - DATABASE 13
Underline attributes are primary keys; italic attributes are foreign keys
October 13, 2024 IT3292E - DATABASE 15
SELECT p.product_id,
p.name
FROM product AS p
LEFT JOIN order_detail AS o
USING (product_id)
WHERE o.product_id IS NULL;
October 13, 2024 IT3292E - DATABASE 16
A SELECT *
FROM User
WHERE YEAR(registration_date) = 2024;
B SELECT *
FROM User
WHERE registration_date >= ‘2024-01-01'::date
AND registration_date <= ‘2024-12-31'::date;
October 13, 2024 IT3292E - DATABASE