我DB具有這樣的結構:更新行,如果count(*)>ñ
ID | text | time | valid
這是我當前的代碼。我試圖找到一種方法來做到這一點作爲一個查詢。
rows = select * from table where ID=x order by time desc;
n=0;
foreach rows{
if(n > 3){
update table set valid = -1 where rows[n];
}
n++
}
我在檢查給定ID有多少行。那麼我需要爲所有行設置有效值= -1,其中n> 3;
有沒有辦法用一個查詢來做到這一點?
見:http://stackoverflow.com/questions/2334712/update-from-select-using-sql-server和http://stackoverflow.com/questions/1262786/mysql-update-query基於選擇查詢 –