Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Laporan prak kum

Database

Disusun oleh : Hari Iskandar

Jurusan teknik elektro


Program studi instrumentasi dan kontrol industri
Politeknik negeri jakarta
Tujuan pembelajaran
 Memahami fungsi-fungsi agregat dan penggunaannya.
 Memahami operasi pengelompokan data.
 Mampu menyelesaikan kasus-kasus yang melibatkan penggunaan fungsi fungsi agregat.
 Mampu menyelesaikan kasus-kasus yang melibatkan penggunaan fungsi fungsi agregat dan
pengelompokan.
La han
Menganalisis duplikasi data
Mendapatkan jumlah data
Mendapatkan jumlah total
Mendapatkan nilai rata-rata
Mencari data minimum
Mendapatkan nilai maximum
Pengelompokan data
Menyaring hasil fungsi agregat
TUGAS PRAKTIKUM
SELECT jenis_buku, nama_buku, MIN(harga) AS harga_termurah : This part specifies the
columns to be selected in the result. It retrieves the book type ( jenis_buku ), book name (nama_buku),
and the minimum price ( MIN(harga)) within each group. FROM penjualan: Specifies the table from
which to retrieve the data, in this case, the "penjualan" table. GROUP BY jenis_buku : Groups the result
set by the book type. This means that the query will calculate the minimum price for each unique book
type.

Then it will display the following results


SELECT jenis_buku, SUM(stok) AS total_stok : This part selects the book type ( jenis_buku)
and calculates the sum of the stock ( SUM(stok)) for each book type. The result is labeled as
total_stok.FROM penjualan: Specifies the table from which to retrieve the data, which is the
"penjualan" table in this case. GROUP BY jenis_buku : Groups the result set by the book type, so the
sum of stock is calculated for each unique book type. HAVING total_stok < 10 : Filters the grouped
results to only include those with a total stock less than 10. This is used in conjunc on with the HAVING
clause, which is similar to WHERE but is applied a er the GROUP BY clause for condi ons on
aggregated values.

Then it will display the following results


This query uses the COUNT func on with DISTINCT to count the number of unique values in
the "nama_mk" column in the "matakuliah" table.

Then it will display the following results


This query uses the SUM func on to calculate the total SKS and the WHERE clause to filter out
the courses with "kode_mk" equal to 'PTI'.

Then it will display the following results


TUGAS RUMAH

SELECT AVG(harga * stok) AS rata_rata_penghasilan_kotor : This part selects the average


gross income, calculated as the average of the product of "harga" (price) and "stok" (stock) for each
book.FROM penjualan: Specifies the table from which to retrieve the data, which is the "penjualan"
table.WHERE stok > 10 : Filters the results to include only rows where the stock is greater than 10.
SELECT jenis_buku, nama_buku, MAX(harga) AS harga_tertinggi : This part selects the
book type, book name, and the maximum price for each group. FROM penjualan: Specifies the table
from which to retrieve the data, which is the "penjualan" table. GROUP BY jenis_buku, nama_buku :
Groups the result set by book type and name. HAVING jenis_buku != 'KOMIK' AND MAX(harga) <
70000 AND SUM(stok) > 16 : Filters the grouped results to include only rows where the book type is
not 'KOMIK,' the maximum price is below 70000, and the sum of stock is greater than 16.

SELECT COUNT(*) AS jumlah_matakuliah : This part selects the count of rows that sa sfy
the given condi ons and labels it as jumlah_matakuliah.FROM matakuliah: Specifies the table from
which to retrieve the data, which is the "matakuliah" table. WHERE nama_mk LIKE '%Sistem%' :
Filters the results to include only rows where the course name contains the word "Sistem." HAVING
jumlah_matakuliah > 3 : Filters the grouped results to include only rows where the count is more than
3.

You might also like