我正在尝试编写此PL SQL查询,以便在输入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 :(得分:0)
试试这个
您只需将查询更改为
即可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
)
此查询为所有员工提供最高薪水的员工。
我希望这可能会有所帮助。