【问题标题】:Using sqlalchemy to query using multiple column where in clause使用 sqlalchemy 查询使用多列 where in 子句
【发布时间】:2014-10-15 16:58:02
【问题描述】:

我希望使用 sqlalchemy 执行此查询。

SELECT name,
       age,
       favorite_color,
       favorite_food
FROM kindergarten_classroom
WHERE (favorite_color,
       favorite_food) IN (('lavender','lentil soup'),('black','carrot juice'));

我只想要喜欢(薰衣草和扁豆汤)或(黑胡萝卜汁)的孩子。此外,这可能是一大堆最喜欢的颜色和食物(可能 > 10K),所以我想大批量地做这些。

这很相似,但并没有完全让我明白: Sqlalchemy in clause

【问题讨论】:

标签: python mysql sql sqlalchemy


【解决方案1】:

你想要tuple_ 构造:

session.query(...).filter(
    tuple_(favorite_color, favorite_food).in_(
        [('lavender', 'lentil soup'), ('black', 'carrot juice')]
    )
)

【讨论】:

  • 是的,这正是我想要的。谢谢。
猜你喜欢
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-06
相关资源
最近更新 更多