17,131
社区成员
有这么一个表,我想查询在当前时间前2小时车号相同,称重方式是毛重,重量相差0.5的所有车辆数据,请问怎么写?万分感谢!
SELECT *
FROM table t1
WHERE
weighing_method = '毛重'
AND EXISTS (
SELECT 1
FROM table t2
WHERE
t1.truck_number = t2.truck_number
AND t2.weighing_method = '毛重'
AND t2.weigh_time >= SYSTIMESTAMP - INTERVAL '2' HOUR
AND t2.weigh_time <= SYSTIMESTAMP
AND ABS(t1.weight - t2.weight) = 0.5
)
AND t1.weigh_time >= SYSTIMESTAMP - INTERVAL '2' HOUR
AND t1.weigh_time <= SYSTIMESTAMP;
采用自连接来查询
SELECT
A.truck_no,
A.weight_type,
A.take_weight,
A.weight_take_time,
B.truck_no as matching_truck_no,
B.weight_type as matching_weight_type,
B.take_weight as matching_take_weight,
B.weight_take_time as matching_weight_take_time
FROM
truck_weights A,
truck_weights B
WHERE
A.truck_no = B.truck_no
AND A.weight_type = '皮重'
AND B.weight_type = '毛重'
AND ABS(A.take_weight - B.take_weight) <= 0.5
AND B.weight_take_time BETWEEN A.weight_take_time - INTERVAL '2' HOUR AND A.weight_take_time
AND A.weight_take_time <= CURRENT_TIMESTAMP;
试一下呢
在数据树上工区下的右键点击“Velocities”,在弹出菜单框内选择“Merge Velocities”,弹出速度合并窗口可进行多块速度合并,使用方法可查看“help”。 (该方法仅限3D工区)