Uas PLSQL
Uas PLSQL
NIM : 41816120085
UAS PL/SQL
Part 1
2. Show the total transactions (volume) and category of each vendors by following these
criteria:
a. Superb: More than 2 SHIPPED and 0 CANCELLED transactions
b. Good: More than 2 SHIPPED and 1 or more CANCELLED transactions
c. Normal: other than Superb and Good criteria Order the vendors by the best category
(Superb, Good, Normal), then by the biggest transaction volume.
SELECT vendor,
CASE
WHEN SUM(CASE when STATUS = 'SHIPPED' then 1 ELSE 0 END) > 2 AND SUM(CASE when
STATUS = 'CANCELLED' then 1 ELSE 0 END) = 0 THEN 'Superb'
WHEN SUM(CASE when STATUS = 'SHIPPED' then 1 ELSE 0 END) > 2 AND SUM(CASE when
STATUS = 'CANCELLED' then 1 ELSE 0 END) >= 1 THEN 'Good'
ELSE 'Normal'
END AS Category,
count(distinct order_id) AS TotalTransaction
FROM transactions
group by vendor;
5. Calculate the average, minimum and maximum of days interval of each transaction (how
many days from one transaction to the next)
1. Show the sum of the total value of the products shipped along with the Distributor
Commissions (2% of the total product value if total quantity is 100 or less, 4% of the total
product value if total quantity sold is more than 100)
SELECT product_name, SUM (quantity * price) VALUE,
CASE
WHEN SUM (quantity) > 100
THEN SUM (quantity * price) * 4 / 100
ELSE SUM (quantity * price) * 2 / 100
END commission
FROM transaction_details
GROUP BY product_name
2. Show total quantity of “Indomie (all variant)” shipped within February 2018
3. For each product, show the ID of the last transaction which contained that particular
product