說明:
floor函數:向下取整,比如floor(2.5) = 2;floor(3.0) = 3;
查詢:
select floor(e2.r/ 2),floor((e2.r-1)/2),e2.* from
(select rownum r, e1.* from
(
select * from nhlh_sto_yggys_mid where f_pkey in (select f_pkey from nhlh_sto_yggys_mid group by f_pkey having count(1) >1) order by f_pkey
) e1
) e2 where floor(e2.r/ 2) >floor((e2.r-1)/2) ;
結果:
解釋:因爲表中沒有行數列,所以首先我們查詢加入行數
select rownum r, e1.* from
(
select * from nhlh_sto_yggys_mid where f_pkey in (select f_pkey from nhlh_sto_yggys_mid group by f_pkey having count(1) >1) order by f_pkey
) e1
然後我們通過取整函數判斷行數除2與行數減1除2的結果對比,從而查詢出所需結果。查詢奇數行也是一樣的道理。