Python操作MySQL实现三目查询方法

Python操作MySQL实现三目查询方法

import pymysql
db=pymysql.connect(
            user='',
            password='',
            host='',
            port=3306,
            database=''
        )

cur=db.cursor()

company=''

company="and xm_company LIKE '%"+ company +"%'" if company!='' else ''

cur.execute("SELECT xm_company FROM xzy_merchants WHERE 1=1 {};".format(company))

print(cur.fetchall())

你可能感兴趣的:(MySQL,Python,python,mysql)