This repository was archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.txt
More file actions
77 lines (52 loc) · 1.87 KB
/
function.txt
File metadata and controls
77 lines (52 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
CREATE TABLE stores(store_id INT PRIMARY KEY AUTO_INCREMENT, store_name VARCHAR(50));
INSERT INTO stores (store_name) VALUES ('Dhaka’);
INSERT INTO stores (store_name) VALUES ('Rangpur');
CREATE TABLE products(product_id INT PRIMARY KEY AUTO_INCREMENT,
product_name VARCHAR(40), cost_price DOUBLE, retail_price DOUBLE,
availability VARCHAR(5));
cost_price – buying price
retail_price – Selling price
availability – LOCAL or ALL office
INSERT INTO products (product_name, cost_price, retail_price, availability)
VALUES ('WIRELESS MOUSE', 200.00, 300.00,'ALL');
INSERT INTO products (product_name, cost_price, retail_price, availability)
VALUES ('8 MP CAMERA', 10000.00, 15000.00,'ALL');
INSERT INTO products (product_name, cost_price, retail_price, availability)
VALUES ('SMART WATCH', 8000.00, 12000.00,'LOCAL');
DELIMITER //
CREATE FUNCTION calcProfit(cost_price double, retail_price double) RETURNS double
BEGIN
DECLARE profit double;
SET profit = retail_price-cost_price;
RETURN profit;
END //
DELIMITER ;
SELECT *, calcProfit(cost_price,retail_price) AS profit FROM products;
DELIMITER //
CREATE FUNCTION ProfitLabel(cost_price double, retail_price double) RETURNS varchar(255)
BEGIN
DECLARE profit double;
DECLARE profitlabel varchar(255);
SET profit = retail_price-cost_price;
if profit>=5000 then
set profitlabel='High';
end if ;
RETURN profitlabel;
END //
DELIMITER ;
SELECT *, calcProfit(cost_price,retail_price) AS profit FROM products;
DELIMITER //
CREATE FUNCTION ProfitLabel2(cost_price double, retail_price double) RETURNS varchar(255)
BEGIN
DECLARE profit double;
DECLARE profitlabel varchar(255);
SET profit = retail_price-cost_price;
if profit>=5000 then
set profitlabel='High';
else
set profitlabel= 'Low';
end if ;
RETURN profitlabel;
END //
DELIMITER ;
SELECT *, calcProfit(cost_price,retail_price) AS profit FROM products;