user1063185
user1063185

Reputation: 115

query for sql server 2005 for getting the 95th percentile of different groups

I have a table like the dummy table described below

Date || Server || Count


1200 || B || 123

1200 || C || 124

1200 || B || 125

1300 || B || 126

1300 || C || 127

1300 || B || 128

1300 || C || 129

I need to write a query to create a table such that I get the 95 percentile of the Count grouped by both Date and Server.

I dont have much experience with Sql, and after looking at the google search results, surfing through countless links I am a bit terrified after seeing a lot of subqueries used.No one is able to give a simple query. Can't we directly use a direct query to get the result like the following?

Date || Server || Count


1200 || B || 123

1200 || C || 124

1300 || B || 126

1300 || C || 127

Can some one please provide the exact query which can be used?

Thanks for the help!!

Upvotes: 1

Views: 622

Answers (1)

Quassnoi
Quassnoi

Reputation: 425391

SELECT  *
FROM    (
        SELECT  *, NTILE(20) OVER (PARTITION BY [date], [server] ORDER BY [count]) AS t
        FROM    mytable
        ) q
WHERE   t < 20

Upvotes: 1

Related Questions