问题
for i in onlycolumns:
if i not in pat and i not in ref:
new=lister.index(i)
value1 = lister[new+1]
query="ALTER TABLE test add %s varchar(30)" %i
cursor.execute(query)
query1 = """ UPDATE test
SET % = %s
WHERE patient_name = %s """
data = (i,value1,value)
cursor.execute(query1, data)
The columns are added dynamically but the values are not updated in it ...any wrong with my update command......value variable here is the name of patient name ...it is right and the value in value1 is 'a'.pLEASE HELP ME ANYONE WITH THE UPDATE COMMAND
回答1:
The problema is with the SET: Use SET %s = %s.
You miss the the s near one %.
来源:https://stackoverflow.com/questions/35956991/python-mysql-dynamic-add-column-and-update-values-in-the-new-columns