insert into t_analysis_green_wave_congest_time_span (green_id,road_direction,week_day,congest_start_time,congest_end_time,congest_index,status,travel_time,speed,peak_type,year_week,week_start_time,week_end_time,insert_time)
SELECT a.green_id,a.road_direction,#{weekDay} as week_day, TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') as congest_start_time,TO_TIMESTAMP(DATE_ADD(#{endTime},INTERVAL '5 MINUTE'),'YYYY-MM-DD HH24:MI:SS') as congest_end_time,AVG(traffic_index),#{status} as status,CEIL(AVG(trval_time)),AVG(speed),
SELECT a.green_id,a.road_direction,#{weekDay} as week_day, TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') as congest_start_time,TO_TIMESTAMP(DATE_ADD(#{endTime},INTERVAL '5 MINUTE')::text,'YYYY-MM-DD HH24:MI:SS') as congest_end_time,AVG(traffic_index),#{status} as status,CEIL(AVG(trval_time)),AVG(speed),
#{peakType} as peak_type,#{weekNumber} as year_week,TO_TIMESTAMP(#{weekStartTime},'YYYY-MM-DD') as week_start_time,TO_TIMESTAMP(#{weekEndTime},'YYYY-MM-DD') as week_end_time,now()
FROM t_greenwave_hist a
where a.start_time between TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') and TO_TIMESTAMP(#{endTime},'YYYY-MM-DD HH24:MI:SS')
sum(status>=3 and status <=4)*60*5 congest_duration,avg(speed) speed,avg(trval_time) travel_time
SUM ( (status >= 3 AND status <= 4)::int )*60*5 congest_duration,avg(speed) speed,avg(trval_time) travel_time
from t_greenwave_hist
where to_timestamp(start_time,'YYYY-MM-DD') BETWEEN to_timestamp(#{startDate},'YYYY-MM-DD') AND to_timestamp(#{endDate},'YYYY-MM-DD')
AND to_timestamp( start_time,'HH24:MI:SS' ) BETWEEN to_timestamp(#{startTime},'HH24:MI:SS' ) AND to_timestamp(#{endTime} ,'HH24:MI:SS' )
where to_timestamp(to_char(start_time, 'YYYY-MM-DD'),'YYYY-MM-DD') BETWEEN to_timestamp(#{startDate},'YYYY-MM-DD') AND to_timestamp(#{endDate},'YYYY-MM-DD')
AND start_time::time BETWEEN #{startTime}::time AND #{endTime}::time
sum(status>=3 and status<=4)*60*5 congest_duration,avg(speed) speed,avg(trval_time) travel_time
from t_greenwave_hist where start_time BETWEEN to_timestamp(#{startDate},'YYYY-MM-DD HH24:MI:SS') AND to_timestamp(#{endDate} ,'YYYY-MM-DD HH24:MI:SS')
SUM ( (status >= 3 AND status <= 4)::int )*60*5 congest_duration,avg(speed) speed,avg(trval_time) travel_time
from t_greenwave_hist
where start_time BETWEEN to_timestamp(#{startDate},'YYYY-MM-DD HH24:MI:SS') AND to_timestamp(#{endDate} ,'YYYY-MM-DD HH24:MI:SS')
(select cross_id from t_greenwave_cross where green_id = #{greenId} and is_key_route = 1 limit 1) cross_data
left join
(SELECT sum(flow) as flow,cross_id from t_cross_dir_data_hist where start_time BETWEEN #{startDate} AND #{endDate} AND TIME( start_time ) BETWEEN #{startTime} AND #{endTime} and dir_type = #{dir} GROUP BY cross_id) cross_flow on cross_data.cross_id = cross_flow.cross_id
left join
(SELECT sum(flow) as flow,cross_id from t_cross_dir_data_hist
where start_time BETWEEN to_timestamp(#{startDate},'YYYY-MM-DD HH24:MI:SS') AND to_timestamp(#{endDate} ,'YYYY-MM-DD HH24:MI:SS')
AND start_time::time BETWEEN #{startTime}::time AND #{endTime}::time and dir_type = #{dir}
GROUP BY cross_id) cross_flow on cross_data.cross_id = cross_flow.cross_id