试图做一个家庭作业问题并且快要完成了,但是我一直遇到这个具体错误。
创建数据库后,说明如下:
添加六行后,创建并运行SQL语句以在customerDB程序中执行以下操作:
客户编号282的信用额度已增加到$ 10,000.00,更新了客户的信用额度。 客户编号725(迪尔菲尔德的四个季节)不再是客户,请从表中删除该客户。 创建一个查询以显示所有客户的姓名和信用额度,该信用额度为$ 10,000或更高,并且rep_num为35。按信用额度降序排列结果。 创建查询以显示余额大于其信用额度的客户的所有信息。
import sqlite3
conn = sqlite3.connect('ABCcorpdatabase.db')
cur = conn.cursor()
cur.execute('DROP TABLE IF EXISTS Customer')
cur.execute(""" CREATE TABLE Customer (customer_number integer,customer_name text,
balance real, credit_limit real, rep_num integer)""")
print()
print('The database and table have been creadted successfully')
Customer = [("148", "Al's Appliance and Sport", "7550.0", "7500.0","20"),
("282", "Brookings Direct", "431.5", "7500.0", "35"),
("462", "Bargains Galore", "3412.0", "10000.0", "65"),
("524", "Kline's", "12762.0", "15000.0", "35"),
("725", "Deerfield's Four Seasons", "248.75", "5000.0", "35"),
("842", "All Season", "8221.0", "7500.0", "20")]
cur.executemany ('INSERT INTO Customer VALUES (?,?,?,?,?)', Customer)
print()
print ('Data was inserted successfully')
sql = """UPDATE Customer SET credit_limit = '10000.00' WHERE customer_number = '282'"""
cur.execute(sql)
print()
print ('Update was successful')
conn.commit()
sql = """DELETE FROM Customer WHERE customer_number = '725'"""
cur.execute(sql)
print()
print('Delete was successful')
conn.commit()
print()
print('Customers with a Credit Limit >= $10,000 and Rep Num of 35: ')
sql = "SELECT credit_limit WHERE credit_limit >= 10000.0"
for row in cur.execute (sql):
print(row)
答案 0 :(得分:3)
sql语句需要FROM子句
sql = "SELECT credit_limit FROM Customer WHERE credit_limit >= 10000.0"
答案 1 :(得分:0)
在从底部开始的第三行中,您犯了一个错误,即未指定要从哪个表中选择credit_limit
。因此,您需要添加一个FROM
子句:
sql = "SELECT credit_limit FROM Customer WHERE credit_limit >= 10000.0"