0% found this document useful (0 votes)
87 views7 pages

Praktikum 2

The document discusses conducting queries on multiple tables and creating views in a database. It provides 10 examples of queries to retrieve and display data from different tables based on joins. It also lists 10 views to create for the database, including views to display product stock levels, sales summaries by product, customer, employee and category, and sales totals by region and country. The objective is for students to be able to perform queries across tables and create object views.

Uploaded by

Jonatan Simbolon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views7 pages

Praktikum 2

The document discusses conducting queries on multiple tables and creating views in a database. It provides 10 examples of queries to retrieve and display data from different tables based on joins. It also lists 10 views to create for the database, including views to display product stock levels, sales summaries by product, customer, employee and category, and sales totals by region and country. The objective is for students to be able to perform queries across tables and create object views.

Uploaded by

Jonatan Simbolon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Praktikum 2 Melakukan Query dan Membuat View

Nama : Yonatan Hidson Simbolon


Nim : 2181024
Objectives:
1. Mahasiswa mampu menampilkan data dari beberapa tabel
2. Mahasiswa mampu membuat Object View

Melakukan Query dari Beberapa Tabel


1. Tampilkan Name Customer dan tanggal berapa saja dia melakukan Order.
SELECT customers.ContactName, orders.OrderDate
FROM customers
INNER JOIN orders ON customers.CustomerID = orders.CustomerID;

2. Tampilkan ProductID, ProductName, SupplierName, SupplierAddress dan SupplierPhone.


SELECT products.ProductID, products.ProductName, suppliers.ContactName, suppliers.Address,
suppliers.Phone
FROM products
INNER JOIN suppliers ON products.SupplierID = suppliers.SupplierID;
3. Tampilkan ProductID, ProductName, CategoryName dan SupplierName.
SELECT products.ProductID, products.ProductName, categories.CategoryName,
suppliers.ContactName
FROM products
INNER JOIN categories ON products.CategoryID = categories.CategoryID
INNER JOIN suppliers ON products.SupplierID = suppliers.SupplierID;
4. Tampilkan productID, ProductName, UnitPrice(order details) dan Quantity (order details)
Coding : SELECT products.ProductID, products.ProductName, `order details`.UnitPrice, `order
details`.Quantity
FROM products
INNER JOIN `order details` ON products.ProductID = `order details`.ProductID;

5. Tampilkan ProductName, frekuensi diorder (dihitung berdasarkan berapa kali Product ID ada di
tabel Order Details), jumlah produk yang laku (dihitung berdasarkan jumlah Quantity masing-
masing produk di Order Details).
Coding : SELECT products.ProductName, COUNT(`order details`.ProductID) AS
FrekuensiOrder, SUM(`order details`.Quantity) AS JumlahLaku
FROM products
LEFT JOIN `order details` ON products.ProductID = `order details`.ProductID
GROUP BY products.ProductName;
6. Tampilkanlah OrderID, EmployeeID dan Nama Employee.
Coding : SELECT orders.OrderID, employees.EmployeeID, employees.FirstName,
employees.LastName
FROM Orders
INNER JOIN employees ON orders.EmployeeID = employees.EmployeeID;

7. Bagian Shipping ingin melakukan pengiriman barang yang diorder. Tampilkan data-data yang
dibutuhkan oleh Bagian Shipping tersebut, seperti tanggal order, nama customer, alamat
customer, kota, nama produk yang diorder dan jumlahnya.
Coding : SELECT Orders.OrderDate, Customers.CompanyName, Customers.Address AS
CustomerAddress,
Products.ProductID, Products.ProductName, `Order Details`.Quantity, `Order
Details`.UnitPrice,
(`Order Details`.Quantity * `Order Details`.UnitPrice) AS TotalHarga
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID
INNER JOIN `Order Details` ON Orders.OrderID = `Order Details`.OrderID
INNER JOIN Products ON `Order Details`.ProductID = Products.ProductID;
8. Bagian penagihan ingin mengirimkan tagihan kepada customer. Tampilkan data-data yang
dibutuhkan oleh bagian penagihan seperti: Tanggal order, nama customer, alamat, daftar barang
(product id dan product name) yang dibeli, jumlah barang, harga barang dan jumlah yang harus
dibayar.
Coding : SELECT Orders.OrderDate, Customers.CompanyName, Customers.Address AS
CustomerAddress,
Products.ProductID, Products.ProductName, `Order Details`.Quantity, `Order
Details`.UnitPrice,
(`Order Details`.Quantity * `Order Details`.UnitPrice) AS TotalHarga
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID
INNER JOIN `Order Details` ON Orders.OrderID = `Order Details`.OrderID
INNER JOIN Products ON `Order Details`.ProductID = Products.ProductID;

9. Tampilkanlah ProductID, Product Name, UnitPrice, Quantity (OrderDetails) dan Pendapatan


(UnitPrice*Quantity) untuk masing-masing product ID
Coding : SELECT Products.ProductID, Products.ProductName, `Order Details`.UnitPrice, `Order
Details`.Quantity,
(`Order Details`.UnitPrice * `Order Details`.Quantity) AS Pendapatan
FROM Products
INNER JOIN `Order Details` ON Products.ProductID = `Order Details`.ProductID;
10. Tampilkanlah IDCategory, Quantity (group) untuk masing-masing CategoryID. Lakukan
grouping untuk kasus ini.
Coding : SELECT Products.CategoryID AS IDCategory, SUM(`Order Details`.Quantity) AS
TotalQuantity
FROM Products
INNER JOIN `Order Details` ON Products.ProductID = `Order Details`.ProductID
GROUP BY Products.CategoryID;
Membuat VIEW di Database
1. Buat VIEW untuk stok produk (ProductID, ProductName, CategoryID, CategoryName,
UnitinStock).
2. Buat VIEW untuk menampilkan produk yang harganya diatas rata-rata (ProductID, ProductName,
HargaRata2, HargaProduct).
3. Buat VIEW untuk produk yang jumlah UnitinStock lebih kecil dibanding dengan ReOrderLevel
bersama dengan SupplierName, Alamat (Address, City, Region, Postal Code) dan Phone.
4. Buat VIEW untuk summary penjualan untuk masing-masing produk: ID produk, Nama produk dan
Quantity, Harga dan Total penjualan.
5. Buat VIEW untuk menampilkan tagihan (OrderID, OrderDate, CustomerID, CompanyName,
AlamatCustomer).
6. Buat VIEW untuk summary penjualan untuk masing-masing Customer (CustomerID,
CustomerName, TotalPenjualan).
7. Buat VIEW untuk summary penjualan untuk masing-masing Sales (EmployeeID, Last Name, First
Name, Title, Alamat.
8. Buat VIEW untuk total penjualan untuk masing-masing categori produk (CategoryID,
CategoryName, Jumlah penjualan).
9. Buat VIEW untuk summary penjualan untuk masing-masing Region (Region, totalpenjualan).
10.Buat VIEW untuk summary penjualan untuk masing-masing Negara (Negara, totalpenjualan).

Gambar :

You might also like