X
X
xaam2018-05-27 23:28:40
MySQL
xaam, 2018-05-27 23:28:40

How to sort null down in GROUP BY?

There is a query
SELECT name, DATE_FORMAT(date, '%Y - %m'), AVG(grade)
FROM `student`
LEFT JOIN `grade` ON student.id = grade.student_id
GROUP BY student.name, DATE_FORMAT(date, ' %Y - %m')
ORDER BY name, DATE_FORMAT(date, '%Y - %m')
outputs like this
Vasya 2018 - 04 4.5
Vasya 2018 - 05 5
Zhanna NULL NULL
Kolya 2018 - 05 4.5
Marina 2018 - 05 1.5
Masha NULL NULL
Petya 2018 - 05 4.5
how to do like this
Vasya 2018 - 04 4.5
Vasya 2018 - 05 5
Kolya 2018 - 05 4.5
Marina 2018 - 05 1.5
Petya 2018 - 05 4.5
Zhanna NULL NULL
Masha NULL NULL

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2018-05-27
@d-stream

The magic all-rounder - case
www.mysqltutorial.org/mysql-case-function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question