1 / 7

SQL-Aggregate dengan Fungsi GROUP, HAVING dan subQuery

SQL-Aggregate dengan Fungsi GROUP, HAVING dan subQuery. Oleh : Devie Rosa Anamisa. Klausa GROUP BY. Mengoperasikan sekelompok baris data menjadi bentuk group data Fungsi Group (Multi-row Function) AVG, COUNT, MAX, MIN, SUM, … Format :

gella
Download Presentation

SQL-Aggregate dengan Fungsi GROUP, HAVING dan subQuery

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SQL-Aggregate dengan Fungsi GROUP, HAVING dan subQuery Oleh : Devie Rosa Anamisa

  2. Klausa GROUP BY • Mengoperasikan sekelompok baris data menjadi bentuk group data • Fungsi Group (Multi-row Function) • AVG, COUNT, MAX, MIN, SUM, … • Format : • SELECT [kolom,] fungsi_group(kolom),… FROM tabel [WHERE kondisi] [GROUP BY kolom] [HAVING kondisi_group] [ORDER BY kolom]; • SELECT avg( salary), max( salary ) , min( salary ) , sum( salary ) FROM employees WHERE job_id LIKE '%_prog‘;

  3. Penggunaan klausa Group by pada lebih dari satu kolom • SELECT department_id, job_id, sum( salary ) FROM employeesGROUP BY department_id, job_id

  4. Klausa HAVING • Identik dengan klausa WHERE • Digunakan untuk membatasi jumlah /memilih baris yang tampil • Klausa WHERE digunakan pada operasi Single-row • Klausa HAVING digunakan pada operasi Multi-row • Penggunaan: • Untuk melakukan pembatasan pada group: • Baris yang digroup kan • Fungsi group yang digunakan • Group yang sesuai dengan klausa HAVING saja yang ditampilkan • Contoh : • SELECT department_id, MAX( salary ) FROM employeesGROUP BY department_idHAVING max( salary ) >3000

  5. SubQuery • Sintak subquery : • SELECT select_list FROM table WHERE expr operator (select select_list from table); • Cara penggunaan subquery: • Letakkan subquery didalam tanda kurung • Tempatkan subquery pada sisi kanan dari kondisi pembandingan • Gunakan operator baris tunggal dengan subquery baris tunggal.

  6. Contoh : • SELECT last_name, job_id, salaryFROM employeesWHERE job_id = ( SELECT job_id FROM employees WHERE employee_id = '7369' ) AND salary < ( SELECT salary FROM employees WHERE employee_id = '7521' )

  7. Terima Kasih

More Related