运行代码时出现以下错误,我不知道原因:
Traceback (most recent call last):
File "python", line 27, in <module>
File "python", line 25, in members_of_circles
sqlite3.OperationalError: no such column: circleCat.name
代码:
import sqlite3
con = sqlite3.connect(":memrory:")
cur = con.cursor()
def creat_tables () :
cur.execute("CREATE table circleCat (id INTEGER PRIMARY KEY, name TEXT,
description TEXT)")
cur.execute("CREATE table members( id INTEGER PRIMARY KEY, name TEXT, level
TEXT, crcl TEXT)")
def add_a_member(name, level, crcl):
cur.execute("INSERT INTO members (name, level, crcl) VALUES (?, ?, ?)" ,
(name, level, crcl));
def add_a_circle(name, description):
cur.execute("INSERT INTO circleCat (name, description) VALUES (?, ?)" ,
(name, description));
creat_tables ()
add_a_circle("Gaming", "for Gaming")
add_a_member("hossam", "beginner", "Gaming")
def members_of_circles():
cur.execute("SELECT name FROM members WHERE members.crcl =
circleCat.name")
members_of_circles()
答案 0 :(得分:1)
您的选择查询错误。试试这个:
def members_of_circles():
cur.execute("SELECT m.name FROM members m, circleCat c WHERE m.crcl = c.name")