“SQL Temukan karyawan gaji tertinggi kedua” Kode Jawaban

SQL Pilih Max Kedua

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 Temukan karyawan gaji tertinggi kedua

/* 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 Gaji tertinggi berdasarkan lokasi

/*  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

Jawaban yang mirip dengan “SQL Temukan karyawan gaji tertinggi kedua”

Pertanyaan yang mirip dengan “SQL Temukan karyawan gaji tertinggi kedua”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya