2017-02-17 69 views
1

我有時間像前:10.45,13.00 現在我需要檢查在在SQL轉換時間爲timestamp

我的查詢是

SELECT T.*, 
    (SELECT a.driver_id 
    FROM tbl_assigned_drivers a 
    WHERE a.vehicle_id=t.id 
    AND a.from_time<=T.time 
    AND a.to_time >=T.time 
    AND a.status='1') AS driver 
FROM 
    (SELECT id, user_id, stime AS TIME, splace, slat, slng, eplace, elat, elng, status, '1' AS TYPE 
    FROM `tb_shifts` 
    UNION ALL SELECT id, user_id, etime AS TIME, eplace AS splace, elat AS slat, elng AS slng, splace AS eplace, slat AS elat, slng AS elng, status, '0' AS TYPE 
    FROM `tb_shifts`) T, 
    tb_shft_veh s, 
    tb_trucks_data t 
WHERE T.time>=11.54 
    AND s.register_number=t.register_number 
    AND s.register_number='AP01TEST' 
    AND s.shft_id=T.id 
    AND s.status='1' 
ORDER BY T.time ASC 

這裏

a.from_time,a.to_time in format of "YYYY-MM-DD HH:MM:SS" 
T.time in format of "HH:MM" 
那個時間日期

現在我需要將T.time轉換爲a.from_time格式

請幫幫我...

+0

[標籤:MySQL的]和[標籤:SQL服務器]是兩個完全獨立的RDBMS產品(帶完全不同的日期時間功能)。選一個。 –

+0

其完整的mysql –

回答

0

感謝所有, 解決查詢是

select T.*,(SELECT a.driver_id FROM tbl_assigned_drivers a WHERE a.vehicle_id=t.id and a.from_time<=CONCAT(CURDATE()," ",REPLACE(T.time, '.', ':'),":00") and a.to_time >=CONCAT(CURDATE()," ",REPLACE(T.time, '.', ':'),":00") and a.status='1') as driver from (SELECT id,user_id,stime as time,splace,slat,slng,eplace,elat,elng,status,'1' as type FROM `tb_shifts` UNION ALL SELECT id,user_id,etime as time,eplace as splace,elat as slat,elng as slng,splace as eplace,slat as elat,slng as elng,status,'0' as type FROM `tb_shifts`) T,tb_shft_veh s,tb_trucks_data t where T.time>=11.54 and s.register_number=t.register_number and s.register_number='AP01TEST' and s.shft_id=T.id and s.status='1' order by T.time asc 

解將是

CONCAT(CURDATE()," ",REPLACE("10.00", '.', ':'),":00")