我試圖更新滿足以下條件的記錄日期列的條件更新表中的記錄:滿足相關同桌
- 列站必須是一樣的站從有記錄FILTER_NR = X !
- 和地位(11,12,13)
- 和FILTER_NR = X
如果x = 3 update語句,我正在尋找,應該從改變表FILTER:
+-----------+------------+---------+---------+
| FILTER_NR | PROBEDATE | STATION | STATUS |
+-----------+------------+---------+---------+
| 1 | 2011-06-01 | 1 | 10 |
| 2 | 2011-06-02 | 1 | 11 |
| 3 | 2011-06-03 | 1 | 12 |
| 4 | 2011-06-04 | 2 | 13 |
+-----------+------------+---------+---------+
到:
+-----------+------------+---------+----------+
| FILTER_NR | PROBEDATE | STATION | STATUS |
+-----------+------------+---------+----------+
| 1 | 2011-06-01 | 1 | 10 | -> not changed
| 2 | 2011-06-01 | 1 | 11 | -> changed
| 3 | 2011-06-03 | 1 | 12 | -> not changed
| 4 | 2011-06-04 | 2 | 13 | -> not changed
+-----------+------------+---------+----------+
我開始用下面的SQL語句,你知不知道我該怎麼完成的呢?
UPDATE FILTER SET PROBEDATE = ADDDATE(PROBEDATE, -1)
WHERE FILTER_NR IN (...);
感謝您的回答,SQL語句正常工作! @Andomar的SQL也是正確的。給我一些時間來決定接受哪個答案。 –