[英]How to sort the time in table using my sql query
如何排序表的時間。 那是從早上6點到晚上10點
name source destination time
gokul xxx yyyy 10.00 PM
abc xxx yyyy 6.00 AM
我在side子查詢中嘗試此查詢仍然無法正常工作
Select * from (
Select * from trips where date = '27-09-2013'
and time like '%PM' or '%pm' ORDER BY time
) AND (
Select * from trips where date = '27-09-2013'
and time like '%AM' or '%am' ORDER BY time
) AS TIME
ORDER BY TIME(time) DESC'
使用此查詢:
SELECT * FROM tabel_name
ORDER BY STR_TO_DATE(`time`,'%h.%i%p');
SQL FIDDLE工作示例。
編輯:
看到您的查詢后,我將為您發布修改后的查詢。
SELECT * FROM trips
WHERE `date` = '27-09-2013'
AND ((`time` like '%PM' OR '%pm')
OR (`time` like '%AM' OR '%am')) ORDER BY STR_TO_DATE(`time`,'%h.%i%p') DESC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.