我有这个查询
SELECT * FROM (select * from VIEW_LARGE_ORDERS WHERE BRANCH = 'BR001') J WHERE ROW_NUM BETWEEN 1 AND 20
现在,当我运行内部查询时,我有超过10,000行。我希望外部查询将内部查询的输出限制为20。
如果我运行整个查询,我会得到7行,即使我知道我应该至少有20行。
请告知我如何解决此问题。
答案 0 :(得分:0)
如果是Oracle SQL,这应该有效:
select * from VIEW_LARGE_ORDERS
where BRANCH = 'BR001' and rownum <= 20
答案 1 :(得分:0)
不需要派生查询。就这样做:
SELECT * FROM VIEW_LARGE_ORDERS WHERE BRANCH = 'BR001' AND ROW_NUM <= 20