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.
我需要编写查询
select count(*) cnt from tabel1,table2 where table1.a=table2.b
它显示计数为 0 1 2
通过使用上面的查询作为子查询,我需要从表 1 中获取 id,其中 count 应该只有 1 和 2 。它不应该为零。
请建议
尝试这个
select a.a , count(b.b) from table1 a join table2 b on a.a = b.b group by a.a having count(b.b) > 0
请试试:
select a.id , count(*) from table1 a join table2 b on a.id = b.id group by a.id having count(*) IN (1, 2)