簡體   English   中英

如何將一個表的ID插入另一個表?

[英]How do I insert an id from one table to another?

我遇到的主要問題是根據用戶不得不猜測的單詞將正確的單詞ID從一個表插入另一個表。

cursor.execute (f"SELECT word_ID FROM WORDS WHERE word = puzzle_to_solve (SELECT puzzle_to_solve FROM WORDS WHERE word = puzzle_to_solve)")
conn.commit()

player_ID = cursor.lastrowid
statistics = (player_ID, word_ID, score)
cursor.execute (f"INSERT INTO STATISTICS ('{player_ID}', '{word_ID}', {score}) VALUES (?, ?, ?)", statistics)
conn.commit()

我希望輸出將正確的玩家ID,單詞ID和得分插入數據庫的表中。 查詢的玩家ID和得分部分確實起作用。

下面提到我收到的錯誤:

sqlite3.OperationalError:在“ SELECT”附近:語法錯誤

該錯誤出現在代碼的select語句行中。

將您的查詢更新為:

cursor.execute (f"SELECT word_ID, player_ID FROM WORDS WHERE word = puzzle_to_solve")
conn.commit()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM