1. 程式人生 > >mysql 實現行號和分頁

mysql 實現行號和分頁

oracle 行號由系統自帶的rownum偽列實現。mysql要實現此功能稍微麻煩一點。如下

SELECT id,name,(@rowNum:=@rowNum+1) as rowNo FROM Area,(Select (@rowNum :=0) ) b

分頁

select * from (SELECT id,name,(@rowNum:=@rowNum+1) as rowNo FROM Area,(Select (@rowNum :=0) ) b) res where rowNo>20 and rowNo<30