开发者

How to orderby before groupby by mysql?

开发者 https://www.devze.com 2023-02-04 00:11 出处:网络
I find the question at mysql order and groupby but it not works, I get the same solution: SELECT * FROM (

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

精彩评论

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