How to orderby before groupby by mysql?
I find the question at mysql order and groupby
but it not works,
I get the same solution:
SELECT *
FROM (
SELECT *
FROM user
ORDER BY create_time DESC
) AS user
GROUP BY user.role
to implement list the newest user开发者_运维知识库 of each role
but mysql's view can't work with subselect.
Mysql doesn't support a first/last function
The answer in the link you provided, is based on the face that HAVING will pick the last item:
SELECT *
FROM user
GROUP BY user.role
HAVING create_time = MAX(create_time)
精彩评论