简体   繁体   English

MySQL ORDER BY日期和团队

[英]MySQL ORDER BY date and team

I would like to order by date and then team in a MySQL query. 我想按日期排序,然后加入MySQL查询。 It should be something similar to this: 它应该类似于以下内容:

SELECT * FROM games ORDER BY gamedate ASC, team_id

AND it should output something like this: 并且它应该输出如下内容:

2010-04-12 10:20 Game 1 Team 1
2010-04-12 11:00 Game 3 Team 1
2010-04-12 10:30 Game 2 Team 2
2010-04-14 10:00 Game 4 Team 1

So that Team 1 is under each other on the same date, but separate on a new date 这样,第1队在同一日期彼此交战,但在新日期分开

Assuming that gamedate is a date field rather than a datetime field, that should work. 假设gamedate是一个日期字段而不是datetime字段,那应该起作用。 If it's a datetime field, you would have to use something like date(gamedate) as the first ordering predicate: 如果它是日期时间字段,则必须使用类似date(gamedate)东西作为第一个排序谓词:

SELECT * FROM games ORDER BY date(gamedate) ASC, team_id ASC

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

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