mysql如何使用不定数量的查询

where in 查询是很常见的,但你知道 python3 中怎么写吗?

话不多说直接上 sample

import pymysql
import config


sql = """
SELECT 
    abc, 
    MAX(last_updated) as last_updated
FROM 
    xxx
WHERE 
    abc IN ({})
"""

class Runner(object):
    ...

    def phone_exist(self, abc):
        sai = []
        placeholders = ", ".join(["%s"] * len(abc))
        query = trovo_sql.format(placeholders)
        self.cursor.execute(query, abc)
        rows = self.cursor.fetchall()
        for row in rows:
            sai.append(row["abc"])
        return sai
        return sai

mysql如何使用不定数量的查询
https://blog.puresai.com/2024/08/16/471/
作者
puresai
许可协议