python3 mysql like 查询
作者:互联网
SELECT fileid FROM files WHERE description LIKE '%%%s%%' OR filename LIKE '%%%s%%' OR uploader LIKE '%%%s%%' ORDER BY fileid DESC" % (search, search, search)
具体示例
def find_info_by_param(self, conn,Title,Organization,InfoType ,PubDate1,PubDate2,offsetnum,limitnum): ''' 根据众多条件返回检索结果,其中包含了mysql的like查询 :param conn: :param Title: :param Organization: :param InfoType: :param PubDate1: :param PubDate2: :param offsetnum: :param limitnum: :return: ''' self.conn = conn result = 0 try: curr = conn.cursor() sqlStr = " select Id,Title,PubDate,Organization,EffectDate,Content,Url,IndexNum,`Type`,PolicyNo,Effect,Keyword,Abstract,InfoType,Creator,CreateTime from Policys where Title like '%%%s%%' and Organization like '%%%s%%' and InfoType ='%s' and (PubDate between '%s' and '%s') limit %s,%s "%(Title,Organization,InfoType,PubDate1,PubDate2,offsetnum,limitnum) print(sqlStr) # args =() curr.execute(sqlStr) rows = curr.fetchall() return rows except pymysql.Error as e: print('find_policy_by_id error %s' % e) conn.close() return result
标签:InfoType,like,Title,param,python3,s%,mysql,%%%,conn 来源: https://www.cnblogs.com/ningy1009/p/12930793.html