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

 

上一篇:[Vivado 12-1345] Error(s) found during DRC. Bitgen not run


下一篇:mysql 报错This function has none of DETERMINISTIC解决方案