测试它:
select sum(t2.fuel_content-t1.fuel_content) TotalFuel,t1.vehicle_id,t1.trip_paramid as rowIdA,
t2.trip_paramid as rowIdB,
t1.creation_time as timeA,
t2.creation_time as timeB,
t2.fuel_content fuel2,
t1.fuel_content fuel1,
(t2.fuel_content-t1.fuel_content) diffFuel
from trip_parameters t1, trip_parameters t2
where t1.trip_paramid<t2.trip_paramid
and t1.vehicle_id=t2.vehicle_id
and t1.vehicle_id=13
and t2.fuel_content-t1.fuel_content>2
order by rowIdA,rowIdB
其中 (rowIdA,rowIdB) 是所有可能的元组,没有重复,diffFuel 是燃料量之间的差,TotalFuel 是所有燃料量的总和。
该查询比较同一车辆的所有燃料含量差异(在此示例中,对于 id=13 的车辆),并且仅当差异燃料大于 2 时对燃料量求和。
问候。