Define a function to execute the first query

def query1(): query = 'SELECT corderNo, dorderdate, s.cshopperId,vFirstName, mTotalCost FROM Shopper AS s, Orders AS a WHERE s.cShopperId=a.cShopperId AND mTotalCost>80;' # Execute the query using your database connection # Return the results (e.g. as a list of dictionaries)

Define a function to execute the second query

def query2(): query = 'SELECT cToyId, vToyName, category FROM Toys AS t, Category AS c WHERE t.cCategoryId=c.cCategoryId;' # Execute the query using your database connection # Return the results (e.g. as a list of dictionaries)

Define a function to execute the third query

def query3(): query = 'SELECT cToyId, VToyName,cBrandName FROM Toys AS t, ToyBrand AS tb WHERE t.cBrandId=tb.cBrandId;' # Execute the query using your database connection # Return the results (e.g. as a list of dictionaries)

Call the appropriate query function based on user input

query_choice = input('Which query do you want to execute? (1, 2, or 3)') if query_choice == '1': results = query1() elif query_choice == '2': results = query2() elif query_choice == '3': results = query3()

Print out the results

for result in results: print(result)

Simplify Database Queries for GlobalToyz - Python Code Example

原文地址: https://www.cveoy.top/t/topic/ojfZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录