Reputation: 1
I have a requirement to give rank based on the column value in table
Condition:
Upvotes: -1
Views: 656
Reputation: 1
select a.*, row_number() over
(partition by Market,Customer order by case
when JobType = '75' then 1
when JobType = '76' then 2
when JobType = '80' then 3
when JobType = '64' then 4
else 5 end , orderCount desc) as rnk
from mytable a
above query worked for me and I am testing it.
Upvotes: 0
Reputation: 5294
You are posting pictures instead of code, but anyway, using row_number()
, rank()
, or dense_rank()
along with a CASE
expression should do it.
Not really following all your logic but something like:
select a.*
, row_number() over (
order by case
when job_type = '1:75' then 1,
when job_type = '2:76' then 2,
when job_type = '3:80' then 3,
when job_type = '4:64' then 4,
else 5 end case,
orderCount desc
) as rnk
from mytable
Upvotes: 0