我有一个名为pmoy.data5min2010的表,列有det_id,time_stamp,speed,volume。我需要查询一个表,包括列:det_id,速度8am,速度在12pm,速度在下午5点,所有这些都在2010年8月11日。按检测器ID排序表,上升。
到目前为止我所拥有的是:
select det_id, speed as t1_speed, speed as t2_speed, speed as t3_speed
From pmoy.data5min2010 where t1_speed = time_stamp '2010-08-11 08:00:00-4'
这给了我det_id列,3个速度列,但它们在t1,t2,t3速度都具有相同的值。如何制作列t1 - 8am数据,t2 - 12pm数据和t3 - 7pm数据?
我的老师说要使用左连接,但我不知道该怎么做。
示例数据
det_id; time_stamp ; speed ; volume
311903; "2010-08-11 05:00:00-04"; 63.7885; 899
311903; "2010-08-11 05:05:00-04"; 63.8465; 859
311903; "2010-08-11 05:10:00-04"; 60.9926; 1007
311903; "2010-08-11 05:15:00-04"; 63.37; 1205
311903; "2010-08-11 05:20:00-04"; 61.5896; 1119