Create a ranking row without using Rank function in SQL

Question

You have to create one more column in predefined table with Name, Id,Department, and Salary.
Now you have to create new column with Rank in it partition by Department

in progress 4
TheDataMonk 55 years 3 Answers 3636 views Grand Master 0

Answers ( 3 )

  1. select 1 + count(*)
    from emp emp1
    where emp1.dept_id = emp.dept_id and
    emp1.salary > emp.salary ;

  2. select name, department, salary,
    (Select count(*)+1 from employee b
    Where b.department=a.department
    and a.salary<b.salary) as rank
    From employee a
    Order by department, salary desc

  3. SELECT Name, Id, Department, Salary,
    (SELECT COUNT(*) + 1 FROM Emp A
    WHERE A.Department = B.Department AND A.Salary > B.Salary) As Rank
    FROM Emp B
    ORDER BY Department, Salary DESC

Leave an answer

Browse
Browse