-- using window partition to group by department
WITH cte_emp AS (
select t.name, t.deptid, t.salary, td.deptname,
rank()OVER ( PARTITION BY t.deptid ORDER BY salary desc) highestsalaryRank
--penggunaan rank over karena di partisi sesuai deptid, jadi hasil salary lebih terstruktur,
--dan duplikat di rank over dihitung sebagai value
--penggunaan dense_rank, maka duplikat tidak akan di anggap value baru, jadi tetap teroganisir secara berurutan
FROM
tblemployee t
join tbldepartment td
on t.deptid = td.deptid
)
SELECT *
FROM cte_emp;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter