www.zhblog.net

PyMySQL中select in写法

最近在使用PyMySQL进行条件in查询时,不知道怎么写。查了下官方文档:

PyMySQL execute有两种可能的形式:

If args is a list or tuple, %s can be used as a placeholder in the query. 

If args is a dict, %(name)s can be used as a placeholder in the query.


示例:

cells = ('cell_1', 'cell_2')

cursor.execute('select count(*) from instance where cell_name in %(cell_names)s;', {'cell_names': cells})

# or alternately

cursor.execute('select count(*) from instance where cell_name in %s;', [cells])



  

展开阅读全文

相关文章

评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 心情