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.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
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