2014-03-25 71 views
0

我一直在尋找這個陳述的年齡,根本找不到錯誤,你們可以幫忙嗎?SQL Date_Sub語法錯誤

 SELECT XD.*, UhED.row_class, 
      (SELECT id 
       FROM Comment C 
       WHERE C.Excel_Data_Excel_Lists_id = XD.Excel_Lists_id 
        AND C.Excel_Data_row = XD.row 
       LIMIT 1 
      ) AS has_activity 
     FROM User_has_Excel_Lists UhXL 
     JOIN Excel_Lists XL 
      ON XL.id = UhXL.Excel_Lists_id 
     JOIN Excel_Data XD 
      ON XD.Excel_Lists_id = XL.id 
     LEFT JOIN User_has_Excel_Data UhED 
      ON UhED.Excel_Data_Excel_Lists_id = XL.id 
       AND UhED.Excel_Data_row = XD.row 
       AND UhED.User_id = 1 
     WHERE UhXL.User_id = 1 
      AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2)<-- it says that the error is here 
     GROUP BY XD.telephone 
     ORDER BY last_name ASC, first_name ASC 
+0

DATE(NOW())有點像CURDATE()?和INTERVAL 2什麼? – Strawberry

+0

你應該提及'日或月或年'''DATE_SUB(DATE(now()),INTERVAL 2)' – jmail

回答

1
AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2 DAY) 

試試這個,它可以幫助你

1

您忘記做指定的時間間隔單元可能?可能是INTERVAL 2 DAYINTERVAL 2 HOUR

0

如果我理解您的問題,請按照以下說明操作: 您應該在以下行中提及日,月,小時或年

代碼:

AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2) 

變化代碼:DAY

AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2 DAY) 

如果你在你的表使用DATE(表名),你得到錯誤如:

錯誤的代碼(樣品)(http://sqlfiddle.com/#!2/5b7e2/7):check代碼NO:5

SELECT id,DATE_SUB(DAT(NOW()), INTERVAL 2 DAY) 
FROM supportContacts; 

權代碼:

SELECT id,DATE_SUB(DATE(NOW()), INTERVAL 2 DAY) 
FROM supportContacts; 

REFER此鏈接:http://sqlfiddle.com/#!2/5b7e2/7