2014-07-02 58 views
2

我有一個表測試並且被如下所示如何使用單where子句

mysql> select * from test; 
+----+------------+------------+---------+-----+------+------+ 
| id | is_deleted | sort_order | version | cid | pid | qid | 
+----+------------+------------+---------+-----+------+------+ 
| 14 |   |   6 |  0 | 1 | 2 | 7 | 
| 18 |   |   1 |  2 | 1 | 4 | 12 | 
| 26 |   |   9 |  0 | 1 | 1 | 1 | 
| 40 |   |   1 |  0 | 1 | 5 | 18 | 
| 49 |   |   2 |  0 | 1 | 5 | 35 | 
| 50 |   |   3 |  0 | 1 | 5 | 39 | 
| 51 |   |   4 |  0 | 1 | 5 | 40 | 
| 61 |   |   10 |  0 | 1 | 1 | 2 | 
| 62 |   |   11 |  0 | 1 | 1 | 3 | 
| 63 |   |   12 |  0 | 1 | 1 | 4 | 
| 64 |   |   13 |  0 | 1 | 1 | 42 | 
| 65 |   |   14 |  0 | 1 | 1 | 43 | 
| 66 |   |   2 |  0 | 1 | 4 | 26 | 
| 67 |   |   3 |  0 | 1 | 4 | 38 | 
| 71 |   |   7 |  0 | 1 | 2 | 2 | 
| 72 |   |   8 |  0 | 1 | 2 | 8 | 
| 73 |   |   9 |  0 | 1 | 2 | 50 | 
| 74 |   |   10 |  0 | 1 | 2 | 51 | 
| 76 |   |   3 |  0 | 1 | 3 | 9 | 
| 78 |   |   4 |  0 | 1 | 3 | 53 | 
| 79 |   |   1 |  0 | 1 | 6 | 54 | 
| 80 |   |   1 |  0 | 1 | 11 | 59 | 
| 81 |   |   1 |  0 | 1 | 12 | 70 | 
+----+------------+------------+---------+-----+------+------+ 

結構欲版本設置爲所有行1,其CID = 1來更新多行,PID不等於到6,11和qid不等於28,59,54

任何人都可以請告訴我該怎麼辦?

回答

4
UPDATE test 
SET `version` = 1 
WHERE cid =1 
    AND pid NOT in(6,11) 
    AND qid NOT IN (28,59,54); 
+1

感謝您的回答,+ 1.I將檢查並讓你知道 – SpringLearner

+0

着它使用'<>'其實我正在從Java QIDS字符串格式如'QID <> 28和QID <完成> 59和qid <> 54' – SpringLearner

+0

是的,你可以做到這一點。 – Sadikhasan