I think this will do it for you . . .drop table Radhikagocreate table Radhika ( DateCol smalldatetime, anotherGrpCol tinyint, waittime int )insert Radhikaselect '01/01/01', 1, 20union select '01/01/01', 1, 13union select '01/01/01', 1, 10union select '01/01/01', 1, 9union select '01/01/01', 1, 8union select '01/01/01', 2, 10union select '01/01/01', 2, 11union select '01/01/01', 2, 12union select '02/01/02', 2, 12union select '02/01/02', 2, 15union select '02/01/02', 2, 20select x.DateCol, x.anotherGrpCol, x.waittime as Medianfrom Radhika x inner join Radhika y on x.datecol = y.datecol and x.anothergrpcol = y.anothergrpcolgroup by x.DateCol, x.anotherGrpCol, x.waittimehaving sum(case when (y.waittime <= x.waittime) then 1 else 0 end) >= (count(*) + 1) / 2 and sum(case when (y.waittime >= x.waittime) then 1 else 0 end) >= (count(*) / 2) + 1go
<O>