Department Wise Employee Ranking With Single T-SQL Query

This code will retrieve the employee details with a salary-wise ranking from each dept.EMP table with different departments and different salaries. If two employees in the same department have the same salary, then they’ll have the same rank.

 EMP Table----------DEPT        NAME                      SALARY$----------- ------------------------- ----------------10          JAMES                     2000.0000010          ADAMS                     1500.0000010          GEORGE                    2000.0000010          JAY                       3000.0000020          LARANCE                   3000.0000020          NICOLES                   4000.0000020          DAVID                     2000.0000020          BORDER                    1500.0000010          BOB                       3000.0000010          SMITH                     1000.00000select b1.dept,,b1.salary$,rank= _(select count(distinct salary$)+1from emp b2 whereb1.dept=b2.dept and b2.salary$>b1.salary$)from emp b1 order by dept,b1.salary$ descResult-------dept      name                   salary$              rank--------- ---------------------- -------------------- -----10        JAY                    3000.00000           110        BOB                    3000.00000           110        JAMES                  2000.00000           210        GEORGE                 2000.00000           210        ADAMS                  1500.00000           310        SMITH                  1000.00000           420        NICOLES                4000.00000           120        LARANCE                3000.00000           220        DAVID                  2000.00000           320        BORDER                 1500.00000           4
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS