0

I'm trying to produce a query on the number of times the product Americano comes up in my database table. My database looks like this:

id  product size    milkOptions

1   Americano   Small   WholeMilk

2   Espresso    Large   SemiSkimmed

This is the query:

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

The error is:

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

1 Answer 1

1

You are checking if product's value is Americano so you need say Americano is a string literal, not just a variable.

Currently you are telling SQL to grab all rows where the product column is equal to the Americano column.

The following should fix that issue:

conn=sqlite3.connect("system.db")
cur=conn.cursor()
americano = cur.execute("""SELECT COUNT(id) FROM customerOrders WHERE product = 'Americano'""")
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Also, how would I print it. When I print the query it does not print the number of times it appears which should be 1. Instead it returns '<sqlite3.Cursor object at 0x091D14E0>'
for x in americano: print(x) or cur.fetchone() should do it. I don't remember off hand and you will need to do some error handling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.