Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sqlite3 python count()查询错误没有此类列_Python_Sql_Sqlite - Fatal编程技术网

sqlite3 python count()查询错误没有此类列

sqlite3 python count()查询错误没有此类列,python,sql,sqlite,Python,Sql,Sqlite,我试图生成一个查询,查询Americano产品在我的数据库表中出现的次数。我的数据库如下所示: id product size milkOptions 1 Americano Small WholeMilk 2 Espresso Large SemiSkimmed 以下是查询: conn=sqlite3.connect("system.db") cur=conn.cursor() americano = cur.execute("""SELECT COUN

我试图生成一个查询,查询Americano产品在我的数据库表中出现的次数。我的数据库如下所示:

id  product size    milkOptions

1   Americano   Small   WholeMilk

2   Espresso    Large   SemiSkimmed
以下是查询:

conn=sqlite3.connect("system.db")
cur=conn.cursor()
americano = cur.execute("""SELECT COUNT(id) FROM customerOrders WHERE product = Americano""")
错误是:

americano = cur.execute("""SELECT COUNT(id) FROM customerOrders WHERE product = Americano""")
sqlite3.OperationalError: no such column: Americano

您正在检查
product
的值是否为
Americano
,因此需要说明
Americano
是字符串文字,而不仅仅是变量

目前,您正在告诉SQL获取
product
列等于
Americano
列的所有行

以下内容可以解决该问题:

conn=sqlite3.connect("system.db")
cur=conn.cursor()
americano = cur.execute("""SELECT COUNT(id) FROM customerOrders WHERE product = 'Americano'""")

谢谢还有,我该如何打印它。当我打印查询时,它不会打印它出现的次数(应该是1)。相反,它在americano中为x返回“
:print(x)
cur.fetchone()
应该这样做。我不记得了,你需要做一些错误处理。