如何获得与元组相似的数据?
我想从类似于元组的表中选择数据。这意味着我只会得到像元组中喜欢的数据,例如T1,
conn = sqlite3.connect('mydatabase.db')
cur = conn.cursor()
result = cur.execute("SELECT Sum(amount) FROM items WHERE id In 't1' ")
c1 = cur.fetchall()
但我会得到此错误: sqlite3.erationalerror:没有这样的表:T1
I want to select data from a table that similar to a tuple. It mean I get just data that like in my tuple for example t1
conn = sqlite3.connect('mydatabase.db')
cur = conn.cursor()
result = cur.execute("SELECT Sum(amount) FROM items WHERE id In 't1' ")
c1 = cur.fetchall()
But I get this error:
sqlite3.OperationalError: no such table: t1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要从表格中选择一个列。
从ID中的项目中选择SUM(量)(从TableName中选择COL1)
如果要获得匹配多个列的值,则内部选择应结合那些列。
从id中的项目中选择“ sum(量)
You need to select a column from the table.
SELECT Sum(amount) From items Where Id In (Select Col1 from TableName)
If you want to get values that match multiple columns, then the inner select should union those columns.
SELECT Sum(amount) From items Where Id In (Select Col1 from TableName Union Select Col2 from TableName)
这里的想法是创建一个具有足够的绑定替换变量的查询,该变量等于元组中的元素数量。
为此,我们需要复制binds
?
。请参阅下面的代码和参考。
The idea here is to create a query with enough bind replace variables which are equal to the number of elements in the tuple.
For that we need to replicate binds
?
.Refer below code and reference.