SQL 中有没有一种方法可以使用与以下内容等效的查询:
select * from table1, table2 where some_join_condition
and some_other_condition and count(distinct(table1.id)) < some_number;
假设 table1 是员工表。然后,联接将导致有关单个员工的数据分布在多行中。我想将返回的不同员工的数量限制为某个数量。在这种情况下,行号或类似条件的条件是不够的。
那么获得与上述查询预期相同的效果和相同输出的最佳方法是什么?
最佳答案
select *
from (select * from employee where rownum < some_number and some_id_filter), table2
where some_join_condition and some_other_condition;
关于SQL 查询限制具有不同值的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4878019/