我有一個MySQL表作爲 表:訂單mysql的可選擇按日期和時間STR_TO_DATE
Order | day | time
1 | Tuesday 31-10-2017 | 10:00 AM
2 | Thursday 02-11-2017 | 11:00 AM
3 | Tuesday 31-10-2017 | 01:00 PM
4 | Tuesday 31-10-2017 | 10:00 AM
5 | Sunday 29-10-2017 | 09:30 AM
我需要根據日期和時間順序進行排序,例如:
Order | day | time
5 | Sunday 29-10-2017 | 09:30 AM
1 | Tuesday 31-10-2017 | 10:00 AM
4 | Tuesday 31-10-2017 | 10:30 AM
3 | Tuesday 31-10-2017 | 01:00 PM
2 | Thursday 02-11-2017 | 11:00 AM
嘗試:
select * from request ORDER BY STR_TO_DATE(time,'%h:%i%p') asc, STR_TO_DATE(day,'%l %d-%m-%Y') desc
但那不是排序預期...
爲什麼使用這種數據類型,而時間戳可以做到這一點沒有任何自定義查詢? – Akam
時區非洲/開羅 –