我有以下sql查询,该查询提供了按月,周和日分组的总h_time。相反,我想要月,周和日的h_time中位数。如何在Oracle SQL中做到这一点?
SELECT DAY, MEDIAN(H_TIME) AS HANDLE_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 HANDLE_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
您的问题可能出在DATE类型携带的时间部分(即使您未明确设置它)。
要摆脱它,您可以使用trunc函数。
代替:
SELECT DAY,
经过:
SELECT trunc(DAY)
和:
GROUP BY DAY
GROUP BY trunc(DAY)