Case Study 1
Case Study 1
USE Case_Study1;
-- 7. Display the details where total expenses are greater than 40.
-- 12. Display the average budget of the Product where the average budget margin
should be greater than 100.
-- Reference
-- 15. Display the table with the following attributes such as date, productID,
product_type, product, sales, profit, state, area_code.
-- 16. Display the rank without any gap to show the sales wise rank.
SELECT *,
DENSE_RANK() OVER (ORDER BY Sales DESC) AS Sales_wise_Rank
FROM Fact;
-- 18. Find the state wise profit and sales along with the product name.
-- 20. Find the maximum profit along with the product ID and producttype.
-- 21. Create a stored procedure to fetch the result according to the product
type from Product Table.
SELECT *,
CASE
WHEN Total_Expenses < 60 THEN 'Profit'
ELSE 'Loss'
END AS Profit_or_Loss
FROM fact
SELECT *,
IIF (Total_Expenses < 60, 'Profit', 'Loss') AS Profit_or_Loss
FROM fact;
-- 23. Give the total weekly sales value with the date and product ID details.
Use roll-up to pull the data in hierarchical order.
-- 24. Apply union and intersection operator on the tables which consist of
attribute area code.
-- 25. Create a user-defined function for the product table to fetch a particular
product type based upon the user’s preference.
-- 26. Change the product type from coffee to tea where product ID is 1 and undo
it.
-- 27. Display the date, product ID and sales where total expenses are between
100 to 200.
-- 28. Delete the records in the Product Table for regular type.
DELETE Product
WHERE Type = 'Regular'
29. Display the ASCII value of the fifth character from the columnProduct.