2013-04-09 119 views
3
team = input("Enter the team name: ") 

cursor = db.cursor() 

sql = "SELECT * FROM `flash_data_archive` WHERE `event_id` IN (SELECT `alternate_id` from `event_list` where `category` = %s)" % team 

cursor.execute(sql) 

什麼是正確的符號有用戶對「團隊」中輸入的字符串用於在SQL subsuery類別字段使用Python變量?在MySQL子查詢

回答

3

從字符串中刪除% team。相反,它應該是.execute的參數。

cursor.execute(sql, team) 

這將正確地逃避它。

+0

修復它,非常感謝! – alpswd 2013-04-09 04:29:53

+1

@alpswd不要忘記註冊並接受有幫助的答案 – 2013-04-09 04:30:33