New Microsoft Word Document
New Microsoft Word Document
-- LAB 6
-- which contains the information about product name and its buying price.
FROM Product;
SELECT Product_Name,
FROM Product;
-- 5. If a salesman does not reach more than 75% of his sales objective, he is labeled as 'Average'.
-- 6. If a salesman does not meet more than half of his sales objective, he is considered 'Poor'.
CASE
WHEN 50.00 <= ROUND((Target_Achieved / Sales_Target) * 100, 2) < 75.00 THEN 'Average'
ELSE 'Poor'
END AS Remarks
FROM Salesman;
from Product
-- 8. Add a new column and find the total quantity for each product.
-- each product is more than 10, change the discount rate to 10 otherwise set to 5.
UPDATE Product
SET Total_Quantity = (
SELECT SUM(Quantity_On_Hand)
FROM SalesOrderDetails
);
UPDATE Product
SET Discount_Rate =
CASE
ELSE 5
END;
-- 10. If the Quantity on hand for each product is more than equal to 20,
UPDATE Product
SET Discount_Rate =
CASE
ELSE 0
END;
-- 11. The first number of pin code in the client table should start with 7.
FROM Clients
-- 1. Creating a view
-- AS
-- select-statement;
-- OR REPLACE - added to overwrite the old view with the same name if applicable.
-- 2. Changing a view
-- 3. Renaming a view
-- 4. Deleting a view
-- 12. Creates a view name as clients_view that shows all customers information from Thu Dau Mot.
-- that shows all clients and their order details from Thu Dau Mot.
SELECT DISTINCT
c.Client_Name,
c.Client_Number,
sod.Order_Number
FROM clients c
-- product in the "Products" table with a sell price higher than the average sell price.
from Product p
-- information and products (product names, product price, quantity order) were sold by them.
SELECT DISTINCT
sm.Salesman_Number,
sm.Salesman_Name,
sm.City,
p.Product_Name,
p.Sell_Price,
sod.Order_Quantity
FROM Salesman sm
-- 17. Creates a view name as sale_view that show all salesman information and product
-- (product names, product price, quantity order) were sold by them with order_status = 'Successful'.
select sm.Salesman_Name,
sm.Salesman_Number,
p.Product_Name,
p.Sell_Price,
sod.Order_Quantity
from Salesman sm
-- 18. Creates a view name as sale_amount_view that show all salesman information and sum order
-- quantity of product greater than and equal 20 pieces were sold by them with order_status =
'Successful'.
select sm.Salesman_Name,
sm.Salesman_Number,
sum(sod.Order_Quantity) >= 20
from Salesman sm
-- 19. Amount paid and amounted due should not be negative when you are inserting the data.