2016-07-06 198 views
1

我正嘗試讓車的形式1表,只需一條件,那就是下一個「的車中有比與相同id_user任何順序更新的」這個SQL查詢有什麼問題?

SELECT pso.* 
FROM lafrips_cart pso 
WHERE pso.id_customer > 0 
AND pso.date_add > (SELECT MAX(pso2.date_add) 
FROM lafrips_orders pso2 
WHERE pso2.id_customer < pso.id_customer) 

我只是比較2場(pso.date_add與ps2.date_add)兩者都是日期時間具有相同的結構

+2

如果他們必須具有相同的用戶標識,爲什麼要說'WHERE pso2.id_customer Siyual

+1

請提供樣本數據和您的預期輸出 –

+0

它已經在我的前面每次...哇... @ Siyual這是錯誤... – ivannaxara

回答

1
SELECT pso.* 
FROM lafrips_cart pso 
WHERE 
    pso.id_customer > 0 
    AND pso.date_add > (
     SELECT MAX(pso2.date_add) 
     FROM lafrips_orders pso2 
     WHERE pso2.id_customer = pso.id_customer 
     ) 
0

爲u兩個所述@Siyual和@Sergio「>」是錯誤,則實際我認爲I'm厚爲磚,我可能還得睡更長時間

SELECT pso.* 
FROM lafrips_cart pso 
WHERE 
pso.id_customer > 0 
AND pso.date_add > (
    SELECT MAX(pso2.date_add) 
    FROM lafrips_orders pso2 
    WHERE pso2.id_customer **=** pso.id_customer 
    ) 

標記**替換爲= =符號