如何从SQL中的另一行获取最小值?



很抱歉,我不能用更好的方式来表达。

我的输出中有以下记录:

<表类> route_id 日期 employee_id stop_type vehicle_stop_number enter_time tbody><<tr>12021-06-16ABC皮卡12021-06-16 15:06:39.00000012021-06-16ABC皮卡22021-06-16 15:27:35.00000012021-06-16ABC跳伞32021-06-16 16:36:42.00000012021-06-16ABC站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;

相关内容

  • 没有找到相关文章

最新更新