今天华数校招,我去笔试,我很惭愧!
上次电话面试的时候对方问我数据分页怎样写?用ORACLE和SqlServer。我当时说了一句特别没脑子的话,我说“Oracle没有页这个概念吧”,更要命的是我还事后居然没有来找答案!今天看到这个问题,我真的要疯了!
今天到网上找了答案,亲自写一下:
MySQL:
select * from table1 limit start , end
例如:select * from table1 limit 10,20
Oracle:
select * from (select t.* ,rownum from table1 t) where rownum between start and end
例如:
select * from (select t.* ,rownum from table1 t) where rownum between 10 and 20
SqlServer:
select * from
(select top n * from
(select top (n+m-1) * from table1 order by id desc
) t1
)t2
order by id asc