“SQL encuentra el segundo empleado salarial más alto” Código de respuesta

SQL SELECT SEGUNDO MAX

Both options you find max as a subset and then exclude from main select
sql> SELECT MAX( col ) FROM table
 	WHERE col < ( SELECT MAX( col ) FROM table);
sql> SELECT MAX(col) FROM table 
WHERE col NOT IN (SELECT MAX(col) FROM table);
Dentedghost

SQL encuentra el segundo empleado salarial más alto

/* sql 2nd highest salary employee */
select sal, ename
from emp
where sal =
    (
        select max(sal) from emp where sal <
            (select max(sal) from emp)
    )
----------------------------------------------- option 2
select *
from 
(
    select ename, sal, dense_rank() over(order by sal desc) rank
    from emp
)
where rank =2;
Wide-eyed Wolf

SQL más alto salario por ubicación

/*  Highest salary by Department/Location   */
SELECT e.ename, e.sal, e.deptno, d.loc
FROM emp e
JOIN dept d
ON e.deptno = d.deptno
WHERE e.sal in
( 	
  	select max(sal) 
  	from emp 
  	group by deptno
)
Wide-eyed Wolf

Respuestas similares a “SQL encuentra el segundo empleado salarial más alto”

Preguntas similares a “SQL encuentra el segundo empleado salarial más alto”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código