Python使用sql语句对mysql数据库多条件模糊查询

1 def find_worldByName(c_name,continent): 2 print(c_name) 3 print(continent) 4 sql = " SELECT * FROM world WHERE 1=1 " 5 if(c_name!=None): 6 sql=sql+"AND ( c_name LIKE '%"+c_name+"%' )" 7 if(continent!=None): 8 sql=sql+" AND ( continent LIKE '%"+continent+"%') " 9 sql=sql+" AND dt=(SELECT dt FROM world order by dt desc limit 1) order by confirm desc " 10 11 # "AND continent LIKE '%%%%%s%%%%'" \ 12 # " order by dt desc " %(c_name,continent) 13 # sql_temp = " SELECT * FROM world WHERE c_name LIKE '%"+c_name+"%' " 14 res = query(sql) 15 list= [] 16 for i in res: 17 # print(i) 18 list.append(i) 19 return list;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpdgjj.html