我想弄清楚如何按小時與以下數據集進行排序。Mysql按時間排序(小時)
hm,total_count,avg_count,max_count
-------------------------------------
'23:15','17','5.6667','9'
'23:45','19','3.1667','5'
'06:15','13','6.5000','9'
'05:15','22','4.4000','7'
'05:45','12','6.0000','11'
'04:15','22','4.4000','6'
'04:45','14','4.6667','7'
'03:45','24','2.4000','5'
'02:45','82','5.4667','13'
'01:45','98','6.1250','13'
'00:45','59','4.2143','11'
我的查詢:
SELECT DATE_FORMAT(`dt`, '%H:%i') as hm, SUM(`counts`) AS total_count,
AVG(`counts`) AS avg_count, MAX(`counts`) AS max_count
FROM pax_load_distribution , plans
WHERE `pax_load_distribution`.`plan_id` = `plans`.`id` AND
`plans`.`dt` BETWEEN '2017-05-01' AND '2017-05-31'
GROUP BY hm
ORDER BY HOUR(hm) DESC, MINUTE(hm) ASC;
但正如你所看到的,查詢組織之上的23個小時,但不是在一個序列從23,00,01,02等。如何使它使得23小時最接近00,01等。
'dt'是否跨越多天? –
是的,它跨越一個月的時間並收集小時。 –