A
A
Altyn Bek2015-10-20 08:14:04
MySQL
Altyn Bek, 2015-10-20 08:14:04

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'

It seems to work, but I can’t set the age for which the list should be displayed, it simply displays all students with a filter and shows the age.
How can I achieve the above result using MySQL?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2015-10-20
@thewind

Are you talking about sorting? Then ORDER BY age ASC

A
Andrey Mokhov, 2015-10-20
@mokhovcom

SELECT * FROM (
    <ваш запрос>
)
WHERE age = 17

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question