2
令人費解了在這一個幾個小時的數字(2-4)的一個循環序列更新數據庫表字段,沖刷谷歌並沒有什麼..如何使用
我試圖更新一個SQL Server表的每一行中的數字(2,3,4)的一個循環序列..
update table
set fieldname = (*black magic*)
where otherfieldname = something
那麼結果將是
other fields|2|other fields|
other fields|3|other fields|
other fields|4|other fields|
other fields|2|other fields|
other fields|3|other fields|
other fields|4|other fields|
other fields|2|other fields|
other fields|3|other fields|
任何想法表示歡迎!
歡呼聲
我現在不在個人電腦上測試,但我想這樣做的計劃效率會比我的答案低,因爲這種排序。另外我不記得NTile是否會添加一個通用的子表達式。 – 2014-09-03 18:37:51
嗯...我不知道他們之間會有很大的區別,他們都是窗口函數,需要在整個結果集中。可能值得測試,但可以用'@@ spid'輕鬆替換'newid()'並測試性能。在一張大桌子上看到結果會很有趣。 – aas4mis 2014-09-03 18:45:34
是的。用@@ spid替換會避免排序。我認爲NTile增加了一個假脫機,儘管這在行號版本中不會出現(儘管在某些情況下該計劃可能還有一個用於萬聖節保護的假脫機) – 2014-09-03 18:50:38