Link to home
Start Free TrialLog in
Avatar of qinyan
qinyan

asked on

How to calculate Median for each group from a large set of data?

I know how to calculate Median from Ken's book 'The Guru's Guide to Transact-SQL', but the example given in the book only deals with one set (group) of numbers. In my case, I need to group by each code and before group by I have a total of 18 million records so using cross join (one way talked about in the book to get Median) might take a long time. If using Identity, i wonder how to insert id which starts 1 again when a new group starts. Thanks!
ASKER CERTIFIED SOLUTION
Avatar of kenhaley
kenhaley

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of qinyan
qinyan

ASKER

I'm using SQL 2005 but it says Rank / Row_Number is not a recognized function name. How could that be? Thanks!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of qinyan

ASKER

I tested on a db running on SQL 2005 and it worked. Thanks!