본문 바로가기
SQL/Oracle

n번째 줄의 데이터 값 조회 SQL

by 젤리씨 2014. 2. 10.
728x90

BEGIN TRY

CREATE TABLE test (

empno INT

, empname VARCHAR(20)

, tel VARCHAR(20)

)

END TRY

BEGIN CATCH END CATCH

INSERT INTO test (empno, empname, tel) VALUES ('1111', '홍길동', '123-4567');

INSERT INTO test (empno, empname, tel) VALUES ('2222', '김철수', '234-5678');

INSERT INTO test (empno, empname, tel) VALUES ('3333', '김영희', '345-6789');

SELECT a.empno, a.empname, a.tel

FROM (

SELECT ROW_NUMBER() OVER ( ORDER BY empno ASC) AS newempno

, empno

, empname

, tel

FROM test

) AS A

WHERE a.newempno = 2 -- 두번째에 있는 행 검색하기

728x90

댓글