我想根据国家/地区列中国家/地区名称的逗号分隔字符串来更新一系列列表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