Professional Documents
Culture Documents
J LAB Eval 2 4th March Solution
J LAB Eval 2 4th March Solution
Databases Management
Semester-IV
2023-24
Lab-Evaluation 2
4th March
2024
Marks: 10 Time: 2 Hour 11:05 AM to 1:10 PM
Name: Abhishek G UEN: 2022UG000045
1. Write a query to display all policy name which has Raksha as a substring.
Solution:
SELECT PName
FROM Policy
WHERE PName LIKE '%Raksha%';
2. Write a query to display all the female agents name who are junior and still working.
Solution:
SELECT Aname
FROM AGENT
WHERE Position = 'Junior'
AND Gender = 'F'
AND EmpStatus = '1';
3. Write a query to display the Total Insurance Sale amount of business done by the agents whose
name has Gowda as a substring.
Example: The Total Insurance Sale of Agent Gowry Gowda is 500000+ 250000 + 300000 =
1050000.
Solution:
SELECT A.Aname, (
SELECT SUM(S.Insurance_Amount)
FROM SALES S
WHERE S.AID = A.AID
) AS Total_Insurance_Sale
FROM AGENT A
WHERE A.Aname LIKE '%Gowda%';
RETURN award;
END
Write a procedure to compute the Premium, Commission and Total Commission for
each business done by the Agent.
Premium= Insurance_Amoutn/Term
Commission = 5% of premium
Total Commission= Commission* Term.
Solution:
CREATE DEFINER=`root`@`localhost` PROCEDURE `ComputeCommission`()
BEGIN
DECLARE done BOOLEAN DEFAULT FALSE;
DECLARE AID_val INT;
DECLARE P_Num_val INT;
DECLARE Insurance_Amount_val DECIMAL(10, 2);
DECLARE Term_val INT;
DECLARE premium_val DECIMAL(10, 2);
DECLARE commission_val DECIMAL(10, 2);
DECLARE total_commission_val DECIMAL(10, 2);
OPEN cur;
read_loop: LOOP
FETCH cur INTO AID_val, P_Num_val, Insurance_Amount_val, Term_val;
IF done THEN
LEAVE read_loop;
END IF;
CALL ComputeCommission();
Or
Query to select:
SET @AID_val = 3;
CALL ComputeCommission(@AID_val, @Premium_val, @Commission_val,
@Total_Commission_val);
SELECT @Premium_val AS Premium, @Commission_val AS Commission,
@Total_Commission_val AS Total_Commission;