很抱歉,我不能用更好的方式来表达。
我的输出中有以下记录:
<表类>
route_id
日期
employee_id
stop_type
vehicle_stop_number
enter_time
tbody><<tr>1 2021-06-16 ABC 皮卡 1 2021-06-16 15:06:39.000000 12021-06-16 ABC 皮卡 2 2021-06-16 15:27:35.000000 12021-06-16 ABC 跳伞 3 2021-06-16 16:36:42.000000 12021-06-16 ABC 站 0 空 表类>
Select route_id, employee_id, stop_type, vehicle_stop_number,
case when enter_time is null and stop_type ='Station' then
(select min(enter_time) from stops where s.route_id = route_id and stop_type = 'Dropoff')
else enter_time end
as enter_time_actuals
from stops s
使用窗口函数:
select s.*,
(case when stop_type = 'Station'
then min(case when stop_type = 'Dropoff' then enter_time end) over (partition by route_id)
else enter_time
end) as imputed_enter_time
from stops s;