存在表T(a,b,c,d),要根据字段c排序后取第21—30条记录显示,请给出sql
SELECT *
FROM (SELECT ROWNUM AS row_num, tmp_tab.*
FROM (SELECT a, b, c, d
FROM T
ORDER BY c) tmp_tab
WHERE ROWNUM <= 30)
WHERE row_num >= 20
ORDER BY row_num;
create table t(a number(,b number(,c number(,d number();
/
begin
for i in 1 .. 300 loop
insert into t values(mod(i,2),i/2,dbms_random.value(1,300),i/4);
end loop;
end;
/
select * from (select c.*,rownum as rn from (select * from t order by c desc) c) where rn between 21 and 30;
/
select * from (select * from test order by c desc) x where rownum < 30
minus
select * from (select * from test order by c desc) y where rownum < 20 order by 3 desc
相比之 minus性能较差
SELECT *
FROM (SELECT ROWNUM AS row_num, tmp_tab.*
FROM (SELECT a, b, c, d
FROM T
ORDER BY c) tmp_tab
WHERE ROWNUM <= 30)
WHERE row_num >= 20
ORDER BY row_num;
create table t(a number(,b number(,c number(,d number();
/
begin
for i in 1 .. 300 loop
insert into t values(mod(i,2),i/2,dbms_random.value(1,300),i/4);
end loop;
end;
/
select * from (select c.*,rownum as rn from (select * from t order by c desc) c) where rn between 21 and 30;
/
select * from (select * from test order by c desc) x where rownum < 30
minus
select * from (select * from test order by c desc) y where rownum < 20 order by 3 desc
相比之 minus性能较差