我试图使用SQL查找中位数。在下面的查询中,我按照" DAY"进行分组,这意味着对于那天的所有h_time,它应该找到中位数,每天只有一个值应该在输出。
SELECT DAY,
MEDIAN(H_TIME) AS H_TIME
FROM(
select
MONTH, WEEK, DAY,
CASE
WHEN C.JOINED IS NOT NULL
THEN (NVL(C.TOTAL_TALK,0) + NVL(C.TOTAL_HOLD,0) + (NVL((C.DATETIME - C.START_DATETIME)*86400,0)) )/86400
ELSE 0 END AS H_TIME
from TABLE1 C
LEFT JOIN TABLE2 S
ON S.ID = C.ID
where c.direct = 'Inbound'
)
where UPPER(ITEM1) like 'SOMETHING%'
GROUP BY
DAY
但是,我得到以下输出:
DAY H_TIME
14-APR-17 .00567129629629629629629629629629629629629
15-APR-17 0
17-APR-17 0
17-APR-17 .00422453703703703703703703703703703703703
19-APR-17 .00269675925925925925925925925925925925925
19-APR-17 0
19-APR-17 0
19-APR-17 .00824074074074074074074074074074074074074
为什么我在同一天获得多行?这意味着中值函数没有按预期工作。