Median and group by

0

Please login or register to vote for this query.

(click on this box to dismiss)

Constructed Languages

Q&A for designers and users of artificial or invented languages, consciously developed instead of having developed naturally

declare @allrequests table
(
  responsetime int,
  period int
)

insert into @allrequests values
(1, 1),
(2, 1),
(3, 1),
(4, 1),
(5, 1),
(1, 2),
(2, 2),
(3, 2),
(1, 3)

select responsetime,
       period
from
  (
    select responsetime,
           period,
           row_number() over(partition by period order by responsetime) as R,
           count(*) over(partition by period) as C
    from @allrequests
  ) T
where R = (C / 2) + 1

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results