10-Course-Database Northwind - 6 With Answers
10-Course-Database Northwind - 6 With Answers
10-Course-Database Northwind - 6 With Answers
Database Northwind
1. Buat stored procedure untuk menampilkan omzet penjualan tiap barang per tahun
exec productperyear
2. Buat stored procedure untuk menampilkan omzet penjualan tiap barang per tahun dengan
parameter kategori
1
DBA – Soetam Rizky - Information System Study Program
categories.categoryname=@CategoryName)
begin
Select top (@Rows) @ProductName=productname,
@ProductID =productid from products,categories
where products.categoryid=categories.categoryid and
categories.categoryname=@CategoryName;
Print cast(@Rows as varchar(5)) + '. Products : ' + @ProductName;
Declare @Rows2 as int;
Set @Rows2 = 1;
while @Rows2<=
(select count(distinct year(orderdate)) from orders)
begin
Select distinct top (@Rows2) @Year=year(orderdate) from orders;
Select @Omzet=sum(quantity*[order details].unitprice)
from orders,[order details],products,categories where
orders.orderid=[order details].orderid and
[order details].productid=products.productid and
products.categoryid=categories.categoryid and
products.productid=@productid and
categories.categoryname=@CategoryName and
year(orderdate)=@Year;
if cast(@Omzet as float)>0
Print @Year + ' : ' +
'Omzet = ' + @Omzet;
Set @Rows2=@Rows2 + 1;
end;
Set @Rows=@Rows + 1;
Print ' ';
end;
go
3. Buat rangkaian prosedur untuk menampilkan data omzet customer yang tertinggi di tiap tahun
2
DBA – Soetam Rizky - Information System Study Program
as
Declare @Rows as int;
Declare @CustomerID as nchar(5);
set @Rows = 1;
while @Rows<=(Select count(distinct year(orderdate)) from orders)
begin
Declare @Year as int;
Declare @CompanyName as nvarchar(50);
Declare @Omzet as varchar(20);
exec highestomzet