数据库表结构
create table test
(
col1 number(8),
col2 date
);怎么根据日期查最近的3条记录?select * (select * from test order by col2) where rownum <=3;
这个SQL语句是可以的,但是会不会导致生成的临时表过大呢?有没有select top 3 * from test类似这种的SQL呢?
create table test
(
col1 number(8),
col2 date
);怎么根据日期查最近的3条记录?select * (select * from test order by col2) where rownum <=3;
这个SQL语句是可以的,但是会不会导致生成的临时表过大呢?有没有select top 3 * from test类似这种的SQL呢?
TOP 3 是SQL SERVER的写法!
ORACLE 只能用select * (select * from test order by col2) where rownum <=3;
临时表过大,怎么会!
--也可以用分析函数,这样写:
select * from
(
select a.*,(row_number() over (order by test )) rm from test a
)
where rm<=3