且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SqlAlchemy:过滤以匹配所有而不是列表中的任何值?

更新时间:2023-02-18 13:17:44

您正在寻找适用于行集的查询.我认为使用带有子句的 group by 是***的方法:

You are looking for a query that works on sets of rows. I think a group by with having clause is the best approach:

select aid
from jt
where bid in (<your list>)
group by aid
having count(distinct bid) = 2

如果您可以将所需的 id 放入表格中,您可以执行以下更通用的方法:

If you can put the ids that you desire in a table, you can do the following more generic approach:

select aid
from jt join
     bids
     on jf.bid = bids.bid
group by aid
having count(distinct jt.bid) = (select count(*) from bids)