產訊2014-08-18日的每小時記錄。 SELECT * FROM `table` where recv_time>='2014-08-20 00:00:00' and recv_time<'2014-08-21 00:00:00' group by date_format(recv_time,'%Y-%m-%d %H')
SELECT a.* FROM `table` a JOIN (SELECT COUNT(1) FROM `table` b ON a.date_format(recv_time,'%Y-%m-%d %H') = b.date_format(recv_time,'%Y-%m-%d %H') WHERE a.revtime > b.revtime)< 1
SELECT id,dtu_name,MIN(recv_time),channel state FROM `table` GROUP BY DATE_FORMAT(recv_time,'%Y-%m-%d %H') ;
这个逻辑不一定非要用SQL完成
用存储过程最好
SELECT * FROM `table` where recv_time>='2014-08-20 00:00:00' and recv_time<'2014-08-21 00:00:00' group by date_format(recv_time,'%Y-%m-%d %H')