Issue
Having trouble with this bit of python code as i am not to sure on how to implement the user inputs gained into the sql statement.
print("What two companies would you like to compare? ")
Company1 = input("What is the first compaany you would like? ")
Company2 = input("What is the second company you would like to add? ")
comData = [Company1, Company2]
carComData = (comData)
cursor.execute("Select * from Cars where (Car_brand like?) or (Car_brand like?) order by car_id",(carComData))
cursor.execute(sql)
result = cursor.fetchall()
df = pd.DataFrame(result, columns=['Car_id', 'Car_Brand', 'Car_Model', 'Year', 'VIN', 'KmsTravelled', 'Price', 'Dealer_id'])
print (df) '''
Solution
Try something like this
cursor.execute("Select * from Cars where (Car_brand like %s) or (Car_brand like %s) order by car_id", (Company1, Company2))
Your problem is you had the parameters in a list instead of a tuple.
Answered By - random
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.