I have a table with the following structure.
create table FindMedians
( GroupByColumn varchar(100)
, TimeInterval_1 int
, TimeInterval_2 int
, TimeInterval_3 int
);
I need to find the medians of each of the time intervals for each group. I've been calculating the medians for each column separately and UNIONing them, and then PIVOTing to get a final result as:
GroupByColumn Median1 Median2 Median3
using a query given in solution to Function to Calculate Median in Sql Server
Note: I'm just using the query, I haven't created a function.
The original table has close 500K rows, and trying to calculate the medians separately for each column is slow. Is there a well performing way that would give me the medians of all the columns in a single query, without having to calculate separately for each column?
Thanks