Article From:

The data table is designed as follows:


SELECT * FROM `xds_message` WHERE  `user_id` = '0a9064ba-711f-5049-9300-c0cc88e1edf7'  AND `delete_time` = 0 GROUP BY to_user_id ORDER BY create_time ASC

The results are as follows:

When I change the ranking rule tocreate_time DESC,give the result as follows

Is there any way to group time?create_timeSort, now after groupingcontentThe values are the first ones. Can we group them in accordance with them?create_timeSort or get the latest one?

Answer 0:

select * from (SELECT * FROM xds_message WHERE  user_id = '0a9064ba-711f-5049-9300-c0cc88e1edf7' AND delete_time = 0 ORDER BY create_time DESC) AS msg_temp GROUP BY msg_temp.to_user_id;

Answer 1:

Operationally, sorting and grouping is fine, but the different database implementations do not necessarily perform the same, but MySQL does

Answer 2:

You can use recordid=1 to get it, Oracle is OK, MySQL and Oracle should be the same.

Leave a Reply

Your email address will not be published. Required fields are marked *