I have a table depart_timings
. It contains dept_time
, station id
, bus_id
. I want to populate another table depart_timings_update
and remove duplicate entries. In new table, there is min_time max_time
and avg_time
etc. fields.
I use the following query:
SELECT * , MIN(dept_time)AS mi, MAX(dept_time) as ma,SEC_TO_TIME(AVG(TIME_TO_SEC(`dept_time`))) as av FROM depart_timings GROUP BY bus_id,station_id ,HOUR(dept_time)"
All are working, but i need to group by dept_time
in an interval of 3 hours. HOUR(dept_time) this query didn't helps to do it. It separates 11:55:00 and 12:00:00 as separate groups. Please help. Sorry for my bad English.
depart_timings
1 bus_id int(20)
2 dept_time time
3 station_id int(20)
4 user_id varchar(100)
5 edit_time timestamp
depart_timings_update
1 bus_id int(20)
2 station_id int(20)
3 min_time time
4 max_time time
5 avg_time time
6 edit_time timestamp