2012-09-28 254 views
1

我需要加入接下來的兩個查詢的結果:加入兩個MySQL查詢

SELECT EXTRACT(HOUR 
FROM (
TIMEDIFF(NOW() , (

SELECT MIN(date_cmd) 
FROM arc_commande_temp 
WHERE id_cmd = '6580')) 
) 
) AS HOURS 

SELECT EXTRACT(MINUTE 
FROM (
TIMEDIFF(NOW() , (

SELECT MIN(date_cmd) 
FROM arc_commande_temp 
WHERE id_cmd = '6580')) 
) 
) AS MINS 

我知道我必須使用加入他們的行列,但不知何故此提取功能給了我很多問題。我有一個仍然有效

SELECT 
    * 
FROM 
    (SELECT 
     MIN(date_cmd) AS HOURS 
    FROM 
     arc_commande_temp 
    WHERE 
     id_cmd = '6580') AS HOURS, 
    (SELECT 
     MIN(date_cmd) AS MINS 
    FROM 
     arc_commande_temp 
    WHERE 
     id_cmd = '6580') AS MINS 
  • 這不是我所需要的下一個查詢,但我試圖修改它來獲得我想要的東西 - 但是當我試圖改變別的東西,以構建查詢我需要......我得到一個錯誤:-(

在此先感謝,並認爲

回答

1
SELECT 
    EXTRACT(HOUR FROM (TIMEDIFF(NOW(), (
     SELECT MIN(date_cmd) 
     FROM arc_commande_temp 
     WHERE id_cmd = '6580' 
    )))) AS HOURS 
    , 
    EXTRACT(MINUTE FROM (TIMEDIFF(NOW() , (
     SELECT MIN(date_cmd) 
     FROM arc_commande_temp 
     WHERE id_cmd = '6580' 
    )))) AS MINS 
+0

好吧,這就是它!非常感謝,Clodo阿爾。 – MiGU