Department Wise Employee Ranking With Single T-SQL Query

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes