简体   繁体   中英

MySQL ORDER BY date and team

I would like to order by date and then team in a MySQL query. 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

Assuming that gamedate is a date field rather than a datetime field, that should work. If it's a datetime field, you would have to use something like date(gamedate) as the first ordering predicate:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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