I have a table called Orders in which the data looks like this:
EMpID OrderValue OrderID 1 100 1 2 167 89 ....
There are multiple orders for each empID.
What I want is to get output in this form
EMPID RANK VALUETOTAL VALUETHISEMPID 1 1 300 100 4 2 300 50\ .....
If there are multiple EmpID(s) With same ValueThisEmpID then it should get same rank.
I tried
SELECT EmpID,SUM(val) OVER() as VALUETOTAL,SUM(val) OVER(PARTITION BY EmpID)
How can I obtain rank and order it by ValueThisEmpID?
First some test data:
You need two steps, one to get empIds and their summed order value. Step two will be to get the total total and rank:
This will give output of:
If you don’t want gaps in the ranking, use dense rank: