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

Masalah dengan pengelompokan

Saya belum menguji, tetapi harus berfungsi:

SELECT case when lag(CUSTOMERS.COMPANY_NAME, 1, null) over 
                 (partition by CUSTOMERS.COMPANY_NAME 
                  order by COMPANY_NAME, COUNT(CALLS.CALL_REF) DESC) is null 
            then CUSTOMERS.COMPANY_NAME else null end cmp_name,
       CUSTOMERS.CUSTOMER_ID AS REF,
       CUSTOMERS.COMPANY_NAME,
       COUNT (CALLS.CALL_REF) AS TOTAL_CALLS,
       CALLERS.CALLER_LAST_NAME AS LAST_NAME,
       COUNT(CALLS.CALL_REF)AS CALLS
  FROM CUSTOMERS
  INNER JOIN CALLERS
    ON COMPANY_ID=CUSTOMER_ID
  LEFT JOIN CALLS
    ON CALLERS.CONTACT_ID=CALLS.CONTACT_ID
  GROUP BY CUSTOMERS.CUSTOMER_ID,
           CUSTOMERS.COMPANY_NAME,
           CALLERS.CALLER_LAST_NAME
  ORDER BY REF, COMPANY_NAME, CALLS DESC;



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Pro dan kontra menggunakan paket di Oracle

  2. Pengaturan NLS_NUMERIC_CHARACTERS untuk desimal

  3. Masukkan xmltype ke xmltype di tempat yang ditentukan [PL/SQL]

  4. LN() Fungsi di Oracle

  5. Bagaimana mengubah format tanggal di database oracle