在SQL和python中使用通配符和IN语法

在SQL和python中使用通配符和IN语法,python,sql,Python,Sql,我想使用通配符检索订单值在包含全部或部分可能值的列表中的客户: sql="SELECT order from `customers` WHERE UPPER(order) IN (%s)" in_p=', '.join(map(lambda x: '%s',orders)) sql = sql % in_p cur.execute(sql,orders) 其中订单是订单的可能值/状态列表。这个查询给出了精确的值 示例:在客户表中,订单的状态值可能为“正在处理”、“正在处理”,但可能的值列表仅

我想使用通配符检索订单值在包含全部或部分可能值的列表中的客户:

sql="SELECT order from `customers` WHERE UPPER(order) IN  (%s)"
in_p=', '.join(map(lambda x: '%s',orders))
sql = sql % in_p
cur.execute(sql,orders)
其中订单是订单的可能值/状态列表。这个查询给出了精确的值

示例:在客户表中,订单的状态值可能为“正在处理”、“正在处理”,但可能的值列表仅包含“正在处理”,我希望检索所有订单

我希望我已经说清楚了。提前谢谢您

您需要SQL运算符:

where = " OR ".join(["order LIKE %s"]*len(orders))
sql = "SELECT order from `customers` WHERE " + where
cur.execute(sql, ["%{}%".format(o) for o in orders])

好主意-我想他们可能会帮助你

orders=['a','b','c']
sql="SELECT order from `customers` WHERE UPPER(order) IN  (%s)"
in_p=', '.join(map(lambda x: str.format('\'{}\'',x),orders))
sql_command = sql % in_p
sql\u命令

SELECT order from `customers` WHERE UPPER(order) IN  ('a', 'b', 'c')

这不是我要找的,查询已经在为精确的值工作了。非常感谢。