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()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter