python如何处理sql中的in
2022-05-21 本文已影响0人
Quick_5413
P_list = [1, 2]
如果in的参数固定:
cursor.execute('select * from users where id in (?,?)', (P_list ))
如果in 的参数不固定,可以这样处理:
cursor.execute('select * from users where id in (' + ','.join('?'*len(P_list)) + ')', (P_list))