Upload presentasi
Presentasi sedang didownload. Silahkan tunggu
Diterbitkan olehTezar Alvin Telah diubah "9 tahun yang lalu
1
PERTEMUAN 10 QUERY KOMERSIAL LANJUTAN Agus Riyanto, S.Kom
2
Menggunakan fungsi Agregat COUNT SUM AVG MIN MAX
3
Contoh Pemakaian Sederhana dari Fungsi Aggregate SELECT Sum (UTS) FROM [Tabel Nilai]SELECT Sum (UTS) FROM [Tabel Nilai] SELECT Count (NIM) FROM [Mahasiswa]SELECT Count (NIM) FROM [Mahasiswa] SELECT Min (Tugas) FROM [Tabel Nilai]SELECT Min (Tugas) FROM [Tabel Nilai] SELECT Max (UAS) FROM [Tabel Nilai]SELECT Max (UAS) FROM [Tabel Nilai] SELECT Avg (UTS * UAS) FROM [Tabel Nilai]SELECT Avg (UTS * UAS) FROM [Tabel Nilai]
4
Sub Query Adalah sub select yang dapat digunakan di klausa where dan having pada pernyataan select luar untuk menghasilkan tabel akhir Aturan-aturan untuk membuat subquery adalah : 1.Klausa Order By tidak boleh digunakan di subquery dan hanya digunakan di pernyataan Select luar. 2.Klausa subquery harus berisi satu nama kolom tunggal atau ekspresi kecuali untuk subquery menggunakan kata kunci EXIST 3.Secara default nama kolom di subquery mengacu ke nama tabel di klausa from dari subquery tersebut 4.Saat subquery adalah salah satu dua operan dilibatkan di perbandingan, subquery hatus muncul disisi kanan perbandingan
5
Contoh Pemakaian GROUP BY dan HAVING SELECT OrderID, Sum (Quantity) FROM [Order Detail] GROUP BY OrderIDSELECT OrderID, Sum (Quantity) FROM [Order Detail] GROUP BY OrderID SELECT OrderID, Min (UnitPrice), Max (UnitPrice) FROM [Order Detail] GROUP BY OrderIDSELECT OrderID, Min (UnitPrice), Max (UnitPrice) FROM [Order Detail] GROUP BY OrderID SELECT OrderID, Sum (UnitPrice * Quantity * (1 - Discount) FROM [Order Detail] GROUP BY OrderIDSELECT OrderID, Sum (UnitPrice * Quantity * (1 - Discount) FROM [Order Detail] GROUP BY OrderID SELECT OrderID, Min (UnitPrice), Max (UnitPrice) FROM [Order Detail] GROUP BY OrderID HAVING OrderID = ‘001’SELECT OrderID, Min (UnitPrice), Max (UnitPrice) FROM [Order Detail] GROUP BY OrderID HAVING OrderID = ‘001’ SELECT OrderID, Sum (UnitPrice * Quantity * (1 - Discount) FROM [Order Detail] GROUP BY OrderID HAVING OrderID = ‘002’SELECT OrderID, Sum (UnitPrice * Quantity * (1 - Discount) FROM [Order Detail] GROUP BY OrderID HAVING OrderID = ‘002’
6
Penggunaan ANY dan ALL Jika subquery diawali kata kunci ALL, syarta hanya akan bernilai TRUE jika dipenuhi semua nilai yang dihasilkan subquery itu. Jika subquery diawali kata kunci ANY, syaratnya akan bernilai TRUE jika dipenuhi sedikitnya satu nilai yang dihasilkan subquery tersebut.
7
Penggunaan EXIST dan NOT EXIST EXIST akan mengirim nilai TRUE jika dan hanya jika terdapat sedikitnya satu baris di tabel hasil yang dikirim oleh subquery dan EXIST mengirim nilai FALSE jika subquery mengirim tabel kosong. NOT EXIST kebalikan dari EXIST
8
Contoh Query Misalkan : Customers ( CustomerID, ContactName, Genre, Address, City, Region, Country, ZIP, Phone ) Products ( ProductID, ProductName, UnitPrice, UnitInStock, UnitOnOrder ) Orders ( OrderID, CustomerID, OrderDate ) Order Detail ( OrderID, ProductID, UnitPrice, Quantity, Discount )
9
Operator dalam SQL Server =,, =, <>=,, =, <> AND, OR, NOTAND, OR, NOT BETWEENBETWEEN LIKELIKE -Simbol mewakili karakter banyak “%” -Simbol mewakili 1 karakter “_” -Simbol himpunan “[ ]” -Simbol range nilai dalam himpunan “-” -Simbol not dalam himpunan “^”
10
Contoh Pemakaian Operator SELECT * FROM Products WHERE UnitPrice > 50000SELECT * FROM Products WHERE UnitPrice > 50000 SELECT * FROM Products WHERE UnitPrice >= 50000 AND UnitPrice = 50000 AND UnitPrice <= 100000 SELECT * FROM Customers WHERE Genre = ‘M’ AND Country <> ‘Indonesia’SELECT * FROM Customers WHERE Genre = ‘M’ AND Country <> ‘Indonesia’ SELECT * FROM Customers WHERE City = ‘Medan’ OR Region = ‘Sumatera Utara’SELECT * FROM Customers WHERE City = ‘Medan’ OR Region = ‘Sumatera Utara’ SELECT * FROM Customers WHERE NOT Country = ‘USA’SELECT * FROM Customers WHERE NOT Country = ‘USA’
Presentasi serupa
© 2024 SlidePlayer.info Inc.
All rights reserved.