ex) 페이징 만드는 순서
select name,basicpay from tblInsa; --원본
select name,basicpay from tblInsa
order by basicpay desc; --원하는 정렬 + 행번호(유효X)
select name,basicpay,rownum from
(select name,basicpay from tblInsa
order by basicpay desc); --원하는 정렬 > 다시 행번호 할당(from절)
select name, basicpay,rownum as 방금만든행번호, rnum as 아까만든행번호
from(select name,basicpay,rownum as rnum from
(select name,basicpay from tblInsa order by basicpay desc))
where rnum between 1 and 10; < where rnum between 11 and 20;>
ex)인구수가 가장 적은 나라 순서대로 3개 가져오기
select * from
(select a.*,rownum as rnum from
(select * from tblCountry
where population is not null
order by population asc) a)
where rnum between 1 and 3;
ex)세대별 그룹
select * from
(select 세대,명,rownum as rnum from
(select floor(age/10)*10 as 세대,count(*) as 명 from tblAddressBook
group by floor(age/10)
order by count(*) desc))
where rnum =3 or rnum =4;
cf) rownum은 항상 from 절이 실행될 때 새로 만들어진다.
'오라클' 카테고리의 다른 글
사용자 계정(SQL) (0) | 2018.09.06 |
---|---|
계층형 쿼리(Hierarchical Query) (0) | 2018.09.06 |
Alter/Drop (DDL) (0) | 2018.09.04 |
인덱스(Index) (0) | 2018.09.04 |
트랜잭션(Transaction) (0) | 2018.09.04 |