2016-07-22 3 views
1

이 PL SQL 쿼리를 작성하여 dpt ID 입력 후 두 번째로 높은 급여를 얻으려고합니다. 이 정보를 함께 넣지 만 dpt ID를 입력 한 후에 쿼리가 실행되지 않습니다.dpt ID 입력 후 두 번째로 높은 급여 받기

CREATE TABLE OUTPUT_LOG 
    (my_column VARCHAR(250)); 
DECLARE 
    v_dpt_id 
BEGIN 
    select dpt_id 
     into v_dpt_id 
    from employees 
    where dpt_id = inticap('&prompt_user'); 
    select salary from 
    (select rownum n,a.* from 
     (select distinct salary from employees order by salary desc) a) 
where n = 2; 
    insert into output_log (my_column) 
    VALUES (||first_name||' '||last_name||' '||salary||); 
end; 
SELECT my_column 
    FROM OUTPUT_LOG; 
+0

는 직원 테이블에서 out 변수 인 v_dpt_id를 사용합니다. –

답변

0

이 쿼리는 자신의 부서에 secode 가장 높은 급여를 가지고 모든 직원을주고

select * from employees where salary in 
(
    select salary from 
    (select rownum n,a.* from 
     (select distinct salary from employees where dpt_id = initcap('&prompt_user') order by salary desc) a 
     ) 
    where n = 2 
) 

등이

간단히 변경할 수 있습니다 쿼리를 시도합니다.

도움이 될 수 있기를 바랍니다.

+0

그것은 작동하고 덜 복잡합니다, 당신을 감사합니다 –

+0

답변이 완벽하면 나에게 최선의 답변 또는 upvote로 표시하십시오. –

관련 문제