How to find median in sql

前端 未结 4 1356
遇见更好的自我
遇见更好的自我 2021-01-24 00:08

I have the following sql query which gives me the total h_time grouped by month, week and day. Instead I want the median h_time for month, week and day. How do I do that in Orac

4条回答
  •  爱一瞬间的悲伤
    2021-01-24 00:58

    Try replacing :

    SUM(H_TIME) AS HANDLE_TIME
    

    by :

    MEDIAN(H_TIME) AS HANDLE_TIME
    

    (line 3)


    EDIT: For the months, replace:

    select 
    MONTH, WEEK, DAY,
    

    By:

    select 
    MONTH,
    

    And:

    GROUP BY
    
    MONTH
    ,WEEK
    ,DAY
    

    By:

    GROUP BY 
    MONTH
    


    For the weeks, replace:

    select 
    MONTH, WEEK, DAY,
    

    By:

    select 
    MONTH, WEEK,
    

    And:

    GROUP BY
    
    MONTH
    ,WEEK
    ,DAY
    

    By:

    GROUP BY 
    MONTH
    ,WEEK
    

提交回复
热议问题