Share
Create a ranking row without using Rank function in SQL
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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
Answers ( 3 )
select 1 + count(*)
from emp emp1
where emp1.dept_id = emp.dept_id and
emp1.salary > emp.salary ;
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
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