![](/img/trans.png)
[英]using python to use names from one sql table to find data in another and then combining the names and data to make an html table
[英]retrieving data from one table and putting into another PYTHON SQL
尝试从数据库中的at表中获取数据并将其插入另一个表中:
获取订单总计并将其分配给变量:
cursor.execute('''SELECT Price FROM Tracks WHERE TrackID = ?''', (trackChoice,))
ordertotal = str(cursor.fetchall())
放入表格中:
cursor.execute('''INSERT INTO Orders(OrderID, Date, OrderTotal, CustomerID, TrackID) VALUES(?, ?, ?, ?, ?)''', (orderID, date,
ordertotal, customerID, trackChoice))
错误:
sqlite3.InterfaceError: Error binding parameter 2 - probably unsupported type.
使用cursor.fetchall(),您可以获取“轨道”中的所有行。 因此,它将具有一个ID以及其他信息。 像这样:(1,“威廉”,“莎士比亚”,“ m”,“无”,“ 1961-10-25”)。 什么是“订单总额”? 我猜会是数字吗? 如果是,并且您正在使用sqlite3,则可以使用row_factory。 有关更多信息,请参见此处的答案: 从Python的sqlite3获取字段值的列表,而不是表示行的元组
为什么不做:
cursor.execute("""
INSERT INTO Orders(name, Date, name, name, name)
VALUES(?, strftime('now'), ?, ?, ?)""",
(value, value, value, value);
也就是说,使用数据库中的当前时间。
(我假设name
实际上是四个不同的列,否则您应该会遇到另一个错误。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.