You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE 'p000%'
mycursor = df.cursor()
income = input("income :")
mycursor.execute("SELECT zip, city, state_name, income_household_median \
FROM sample\
WHERE income_household_median > LIKE '%" income "%' \
ORDER BY income_household_median DESC")
myresult = mycursor.fetchall()
for x in myresult:
print(x)
CodePudding user response:
You can not combine > with like and that is why will go wrong and switch to replacements
mycursor = df.cursor()
income = input("income :")
mycursor.execute("SELECT zip, city, state_name, income_household_median \
FROM sample\
WHERE income_household_median > %s \
ORDER BY income_household_median DESC",( income,))
myresult = mycursor.fetchall()
for x in myresult:
print(x)
CodePudding user response:
The error is in the greater than sign before the like
Must be:
mycursor.execute("SELECT zip, city, state_name, income_household_median \
FROM sample\
WHERE income_household_median LIKE '%" income "%' \
ORDER BY income_household_median DESC")