1

如何按时间对表格进行排序。即从早上 6 点到晚上 10 点

 name    source destination time 
 gokul   xxx    yyyy        10.00 PM
 abc     xxx    yyyy        6.00 AM

我在侧子查询中尝试了这个查询仍然无法正常工作

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' 
4

1 回答 1

3

使用这个查询:

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
于 2013-09-27T11:11:57.853 回答