Examine the following database design. This database is stored in our working directory in a file called Northwind2020.db
Mon Mar 27 2023 11:18:57 GMT+0000 (Coordinated Universal Time)
Saved by
@kalvadet
#python
#sql
import sqlite3
conn = sqlite3.connect('Northwind2020.db')
def CustOrderCountDetails(CustomerID):
cursor = conn.cursor()
cursor.execute("SELECT FirstName, LastName, COUNT(*) FROM Customer JOIN [Order] ON Customer.Id = [Order].CustomerId WHERE Customer.Id = ? GROUP BY Customer.Id", (CustomerID,))
result = cursor.fetchone()
conn.close()
return f"Customer {result[0]} {result[1]} had a total of {result[2]} orders"
import sqlite3
conn = sqlite3.connect('Northwind2020.db')
def CustOrderCountDetails(CustomerID):
# Your code goes here
cursor = conn.cursor()
SQL = '''SELECT FirstName, lastname, COUNT([Order].Id) as OrderCount
From Customer, [Order]
WHERE customer.id = CustomerId
and customer.id = :Cid
GROUP BY FirstName, LastName'''
result = cursor.execute(SQL,{'Cid': CustomerID}).fetchone()
return "Customer " + result[0] + " " + result[1] + " had a total of " + str(result[2]) + " orders"
cursor.close()
content_copyCOPY
Comments