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

Oracle SQL - Permintaan untuk menghitung nilai dari beberapa tabel

Anda dapat menggunakan beberapa ekspresi tabel umum, menghitung masing-masing secara terpisah dan menggabungkannya - hanya agar Anda memahami apa yang terjadi.

SQL Fiddle

Kueri :

WITH aud(manager_email,Total_audits) AS
  (SELECT manager_email,
    SUM (
    CASE
      WHEN audit_eligible = 'Y'
      THEN audits_required
    END )
  FROM REQUIRED_AUDITS
  GROUP BY manager_email
  ),  --Total_audits

  scores(manager_email,Audits_Performed) AS
  (SELECT manager_email,
    COUNT ( ID )
  FROM SCORE_ENTRY s
  GROUP BY manager_email
  )  --Audits_Performed

SELECT h.manager_email manager,
  a.Total_audits,
  s.Audits_Performed,
  100 * s.Audits_Performed / a.Total_audits percentage_complete
FROM HR h
LEFT OUTER JOIN aud a
ON h.manager_email = a.manager_email
LEFT OUTER JOIN scores s
ON h.manager_email = s.manager_email
ORDER BY 2 DESC NULLS LAST 

Hasil :

|       MANAGER | TOTAL_AUDITS | AUDITS_PERFORMED | PERCENTAGE_COMPLETE |
|---------------|--------------|------------------|---------------------|
|  [email protected] |           10 |                1 |                  10 |
| [email protected] |            9 |                2 |   22.22222222222222 |
| [email protected] |       (null) |           (null) |              (null) |
|  [email protected] |       (null) |           (null) |              (null) |
| [email protected] |       (null) |           (null) |              (null) |


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. [01000][unixODBC][Driver Manager]Tidak dapat membuka lib '/usr/local/easysoft/Oracle/InstantClient112/lib/libsqora.so' :file tidak ditemukan

  2. Karakter kosong diabaikan di klausa where

  3. OC4J 10.1.3.3 tidak dapat menemukan ojms.rar menyiapkan kegigihan basis data

  4. Hal Yang Harus Anda Ketahui Sebelum Mempelajari Oracle

  5. Perbarui beberapa kolom dalam pernyataan MERGE ORACLE