简体   繁体   English

MySQL-按日期排序,然后按标题整理

[英]MySQL - ORDER BY date, then collate by title

I wish to sort my results into groups (but not GROUP BY , just collated) of column title, and within each group they would be sorted by date. 我希望将结果分类为列标题的组(但不是GROUP BY ),并且在每个组中它们将按日期排序。 The groups would be ascending in date. 这些团体在日期上会上升。

I thought a simple ORDER BY date, title would suffice, but this does not work as expected. 我以为简单的ORDER BY date, title就足够了,但这不能按预期工作。

You can see my data here: http://sqlfiddle.com/#!2/658f7c/11 The rows with the message column containing Old (...) should appear first, while the ones containing New (...) should appear later (within the groups, they should be sorted by date). 您可以在此处看到我的数据: http : //sqlfiddle.com/#! 2/658f7c/11带有消息列的包含Old (...)应首先出现,而包含New (...)应出现稍后出现(在组内,它们应按日期排序)。

The expected output should be below. 预期输出应低于。 Note: the date should always be ascending. 注意:日期应始终为升序。

Title  |  Message     | Date
-----------------------------
Old    |  Old (One)   | 0001
Old    |  Old (Two)   | 0002
Old    |  Old (Three) | 0029
New    |  New (One)   | 0002
New    |  New (Two)   | 0003
New    |  New (Three) | 0004

Try this: 尝试这个:

SELECT title, message, post_id, user_id, post_date
FROM `table`
ORDER BY title DESC, post_date ASC

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM