Answer the question
In order to leave comments, you need to log in
How to list students in MySQL by age?
Good day to all! There is a table in a DB, is more specific in MySQL. There is such a task that it is necessary to alternately display a list of students who are currently 17,18,19, etc. possible by separate requests.
Found the following code:
SELECT
lastname,
name,
middlename,
birthday,
(
(YEAR(CURRENT_DATE) - YEAR(birthday)) -
(DATE_FORMAT(CURRENT_DATE, '%m%d') < DATE_FORMAT(birthday, '%m%d'))
) AS age
FROM student
WHERE group_code='group_code'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question