Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 2 个表:线程和成员。
表线程:id | 姓名 | ...
表成员:id | 线程ID | 姓名 | ...
线程可以有 2 个或更多成员。成员可以存在于不同的线程中。我想要一个线程,它只有 2 个成员,其中一个成员的名字是 AAA。
DB:android 中的 sqlite。
使用带有having子句的聚合:
having
select m.ThreadId from members m group by m.ThreadId having count(*) = 2 and sum(case when m.name = 'AAA' then 1 else 0 end) = 1;