请问Python Mysql怎么使用多条件搜索内容呢? 为什么我使用字符串拼接后搜索会报错呢? 搜索的两个字段都是varchar
cur = con_mysql.cursor()
#能正确返回结果
search_info = "select * from db_log where log_time = '2022-08-19 07:00:00至2022-08-19 20:30:00'"
search_info = "select * from db_log where log_area = '西南路一段'"
#未查询到,返回空
search_info = "select * from db_log where log_time = '2022-08-19 07:00:00至2022-08-19 20:30:00' and log_area = '西南路一段'"
#报错
#(1064, '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 \'"select * from db_log where log_time = 2022-08-19 07:00:00至2022-08-1\' at line 1')
#"select * from db_log where log_time = 2022-08-19 07:00:00至2022-08-19 20:30:00"
aaa = "2022-08-19 07:00:00至2022-08-19 20:30:00"
search_info = '''"select * from state_db_log where log_time = ''' + aaa + '''"'''
cursor.execute(search_info)
res_search = cursor.fetchall()
print(res_search)