Files
sql_advanced/lab9-12-test/task7.sql
T
Vitalii Litvinchuk 0d93a18aad
Advanced SQL Quality Check / Lint SQL Scripts (push) Failing after 18s
feat: test 9-12
2026-05-06 23:35:17 +03:00

36 lines
1.5 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#####################################################
###################### Task 7: ##################
1. Створіть збережену процедуру під назвою GetProfit, яка повертає загальний прибуток, отриманий
від певного продукту за певний рік. В якості параметрів процедури користувач повинне ввести значення
для ProductID та року.
Наприклад, результат процедури GetProfit із ProductID="P1" і 2020 роком показано на скриншоті нижче:
https://drive.google.com/open?id=18W3lTIs6yJlSw99k6uq1g5oPhSqLnd63&usp=drive_fs
set @ProductID = "P1", @year = 2020;
select * from Products;
select * from Orders;
drop procedure GetProfit;
create procedure GetProfit(in inputYear int, in inputProductId varchar(10))
begin
declare TotalProfit float default 0;
select round(sum(SellPrice * Quantity - (BuyPrice * Quantity)), 2)
into TotalProfit
from Orders
join Products on Orders.ProductID = Products.ProductID
where YEAR(Date) = inputYear and Products.ProductID = inputProductId;
select TotalProfit as profit;
end;
2. Виведіть значення процедури для кількох різних параметрів.
call GetProfit ("2020", "P1");
call GetProfit ("2020", "P2");
call GetProfit ("2020", "P3");