请帮助我在Oracle数据库中编写一个SQL查询。有一个名为tbl的表,它有12行。我想先选择前4行,然后选择下4行和后4行。
任何人都可以告诉我如何在Informix中执行此操作。
您可以使用rownum:
rownum
select * from (select t.*, rownum rn from tbl t) where rn between 1 and 4; / select * from (select t.*, rownum rn from tbl t) where rn between 5 and 8; / select * from (select t.*, rownum rn from tbl t) where rn between 9 and 12; /
如果您正在使用order by子句,请使用row_number()(documentation)
order by
row_number()
select * from (select t.*, row_number() over (order by column_name) rn from tbl t) where rn between 1 and 4; / select * from (select t.*, row_number() over (order by column_name) rn from tbl t) where rn between 5 and 8; / select * from (select t.*, row_number() over (order by column_name) rn from tbl t) where rn between 9 and 12; /