我想根據國家/地區列中國家/地區名稱的逗號分隔字符串來更新一系列列表Country1
,Country2
... Country 9
。我有以下statment這樣做:如何使用多個條件的單條語句更新多列
cur.execute("\
UPDATE t \
SET Country1 = returnCommaDelimitedValue(Country,0),\
Country2 = returnCommaDelimitedValue(Country,1),\
...
Country10 = returnCommaDelimitedValue(Country,9),\
WHERE Country IS NOT NULL\
;")
我也有我的田部命名爲Genre
列。現在我想更新列表Genre1
,Genre2
... Genre9
在同一個語句。我認爲該陳述看起來像這樣:
cur.execute("\
UPDATE t \
SET Country1 = returnCommaDelimitedValue(Country,0), Genre1 = returnCommaDelimitedValue(Genre,0)\
Country2 = returnCommaDelimitedValue(Country,1), Genre2 = returnCommaDelimitedValue(Genre,1)\
...
Country10 = returnCommaDelimitedValue(Country,9), Genre10 = returnCommaDelimitedValue(Genre,9)\
WHERE Country IS NOT NULL\
AND Genre IS NOT NULL
;")
該陳述是否正確?
這是可怕的表設計。你能改變它嗎? –
不知道我能不能,爲什麼這麼可怕? –
您的意思是'Genre1 = returnCommaDelimitedValue(Genre,0)'而不是'Genre1 = returnCommaDelimitedValue(Country,0)'? – redneb