Averaging dates in oracle sql

后端 未结 4 1666
逝去的感伤
逝去的感伤 2020-12-10 07:06

Is there a way to average multiple dates in oracle? avg doesn\'t do any good.

Thanks.

4条回答
  •  醉酒成梦
    2020-12-10 07:35

    The 'median' function in oracle in a neat way does exactly what other answers do.

    Here is a link to the Oracle documentation - https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions086.htm

    It can take as an arg a numeric datatype or a non-numeric datatype that can be converted implicitly to a number.

    SQL> desc x1
    Name                                      Null?    Type
    ----------------------------------------- -------- ----------------------------
    A                                         NOT NULL NUMBER
    D                                                  DATE
    
    SQL> select * from x1;
    
         A D
    ---------- ---------
         1 11-DEC-14
         2 13-DEC-14
         3 22-DEC-14
         4 02-DEC-14
    SQL> select median(d) from x1;
    
    MEDIAN(D)
    ---------
    12-DEC-14
    

提交回复
热议问题