Adding a number id to a table

SELECT top 5
day_description,
count(numberofdays) as number

FROM mytable

where department = 'departmentname'

group by day_description

my select brings something like this back:

day description           number           
holiday                     32               
working day                 212              
training day                5                
meeting day                 26               
admin day                   66   

Is there a way of adding an new column where it asigns either 1-5, 1 being the highest value row, and 5 being the lowest value row. And looks like this:

day description           number           top5ID
holiday                     32               3
working day                 212              1
training day                5                5
meeting day                 26               4
admin day                   66               2

Answers


Maybe something like this:

;WITH CTE
AS
(
    SELECT top 5
        day_description,
        count(numberofdays) as number
    FROM mytable
    where department = 'departmentname'
    group by day_description
)
SELECT
    ROW_NUMBER() OVER(ORDER BY CTE.number DESC) AS Top5ID,
    CTE.*
FROM
    CTE

Or without CTE:

SELECT
    ROW_NUMBER() OVER(ORDER BY t.number DESC) AS Top5ID,
    t.*
FROM
    (
        SELECT top 5
        day_description,
        count(numberofdays) as number
        FROM mytable
        where department = 'departmentname'
        group by day_description
    ) AS t

Need Your Help

How do you configure a WCF service for clients running on networked machines?

c# c#-3.0 wcf wcf-binding

I’ve just created a WCF service/client and it all works fine when running on the same machine. But can’t figure out how to configure it to run on different machines. Do you know how?