慕妹3242003
您想要的SQL是select name from studens where id in (1, 5, 8)如果您想要从python构建这个结构,您可以使用l = [1, 5, 8]sql_query = 'select name from studens where id in (' + ','.join(map(str, l)) + ')'这个地图函数将列表转换为字符串列表,这些字符串可以通过逗号使用加入方法。另一种选择是:l = [1, 5, 8]sql_query = 'select name from studens where id in (' + ','.join((str(n) for n in l)) + ')'如果你愿意生成器表达式映射函数。最新情况:S.Lott注释中提到PythonSQLite绑定不支持序列。在这种情况下,你可能想select name from studens where id = 1 or id = 5 or id = 8产生于sql_query = 'select name from studens where ' + ' or '.join(('id = ' + str(n) for n in l))