如何从mysql中的多个相同日期获取最新的日期时间

时间:2013-02-08 08:00:15

标签: mysql sql group-by

如何从mysql中的多个相同日期获取最新的日期时间?

SELECT start_time FROM times WHERE start_time BETWEEN '2013-01-27' AND '2013-02-02' ORDER BY start_time

此输出:

2013-01-27 00:00:00 
2013-01-28 09:00:00 
2013-01-29 00:00:00 
2013-01-30 09:00:00 
2013-01-31 00:00:00     
2013-02-01 09:00:00      
2013-02-01 21:00:00      
2013-02-02 00:00:00 

我希望所有这些输出除了我想要2013-02-01的最新日期时间 所以输出会这样:

2013-01-27 00:00:00 
2013-01-28 09:00:00 
2013-01-29 00:00:00 
2013-01-30 09:00:00 
2013-01-31 00:00:00          
2013-02-01 21:00:00  <<<<<<<<    
2013-02-02 00:00:00 

1 个答案:

答案 0 :(得分:5)

SELECT MAX(start_time)
FROM times 
WHERE start_time BETWEEN '2013-01-27 00:00:00' AND '2013-02-02 23:59:59' 
GROUP BY DATE(start_time)
ORDER BY start_time