Grouped by age first category B lesson
Anonymous
mysql
12/08/2021 3:46 PM
524 B
20
Indexable
SELECT TIMESTAMPDIFF(YEAR, birthday, ( SELECT `start` FROM lessons WHERE student_id = students.id AND category = 'B' ORDER BY `start` ASC LIMIT 1)) AS age, count(*) AS total FROM students WHERE birthday IS NOT NULL AND deleted_at IS NULL AND EXISTS ( SELECT * FROM lessons WHERE student_id = students.id AND category = 'B') GROUP BY age
Editor is loading...