if you're grouping by date, i don't think you should use 'distinct(date)'. i can't give you a great answer though without trial and error queries against your data.
i did lookup the calculation for median and it looks like you may be missing 1 thing.
this page says to add 1 to the count of the array before dividing it by 2.
example for the array would be this:
PHP Code:
<?
$array = array(22, 33, 44, 55, 66, 77, 88, 99);
// array count + 1 then divided by 2 and rounded down.
// then subtract 1 to use with a zero based array
$array_key = floor((count($array)+1)/2)-1;
$median = $array[$array_key];
?>
that's how i understood it anyway. i don't think i could be much more help on the query though.