开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜