Oracle
 sql >> Teknologi Basis Data >  >> RDS >> Oracle

Oracle SQL - max() dengan nilai NULL

max(end_dt) keep (dense_rank first order by end_dt desc nulls first)

pembaruan:

SQL Fiddle

Pengaturan Skema Oracle 11g R2 :

CREATE TABLE t
    (val int, s date, e date)
;

INSERT ALL 
    INTO t (val, s, e)
         VALUES (1, sysdate-3, sysdate-2)
    INTO t (val, s, e)
         VALUES (1, sysdate-2, sysdate-1)
    INTO t (val, s, e)
         VALUES (1, sysdate-1, null)
    INTO t (val, s, e)
         VALUES (2, sysdate-1, sysdate-.5)
    INTO t (val, s, e)
         VALUES (2, sysdate-.5, sysdate-.25)
SELECT * FROM dual
;

Kueri 1 :

select val, min(s), max(e) keep (dense_rank first order by e desc nulls first)
from t group by val

Hasil :

| VAL |                          MIN(S) | MAX(E)KEEP(DENSE_RANKFIRSTORDERBYEDESCNULLSFIRST) |
---------------------------------------------------------------------------------------------
|   1 | November, 13 2012 14:15:46+0000 |                                            (null) |
|   2 | November, 15 2012 14:15:46+0000 |                   November, 16 2012 08:15:46+0000 |


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. SQL Oracle Menghitung Cluster

  2. Contoh String dan Angka Oracle Concatenate

  3. Apa perbedaan antara pls_integer dan binary_integer?

  4. Menghapus angka nol di depan dari pengembang varchar sql

  5. ORA-12704:ketidakcocokan set karakter