Test Index

CBSE Class 12 Computer Science 2026 Paper Set 4 Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 34 of 37
Marks: +1, -0
Assume that you are the Manager of the Loans department of a Finance House. To keep track of the loans you have created two tables : CUSTOMERS and LOANS. The sample data in these tables is given below :
Table: CUSTOMERS
C_IDC_NamePhone
00001Raj Malhotra1234567890
00003David Xavier3456789012
00004Damini Iyer3156789012
00008Abdul2345678901
Table: LOANS
SNoC_IDL_AmtL_DateTermsRoI
1000032000002025-12-06607.80
20000825000002023-08-09609.00
3000015000002025-08-13486.00
4000033000002026-12-07368.00
5000046000002026-12-07606.00
Note : The tables may contain more records than shown here.
The management of the Finance House needs certain reports from you. Write the queries to extract the following data to create the reports :
(i) Number of records from LOANS table where Rate of Interest (RoI) is above 7.0.
(ii) Names of the customers whose loan amount (L_Amt) is above 1000000.
(iii) C_ID, C_Name and Terms of all those records where Loan Date (L_Date) is after 31st December, 2024.
(iv) (a) Details of all the loans in the descending order of RoI.
OR
(b) C_ID and average term for each C_ID from the LOANS table.
Solution:  
Concept: C_Name is in CUSTOMERS while L_Amt, L_Date and Terms are in LOANS, so parts (ii) and (iii) join the two tables on the common column C_ID (equi-join).
(i)
SELECT COUNT(*) FROM LOANS
WHERE RoI > 7.0;
For the sample data this gives 3 (RoI 7.80, 9.00, 8.00).
(ii)
SELECT C_Name
FROM CUSTOMERS, LOANS
WHERE CUSTOMERS.C_ID = LOANS.C_ID
AND L_Amt > 1000000;
For the sample data this gives Abdul (loan of 2500000).
(iii)
SELECT CUSTOMERS.C_ID, C_Name, Terms
FROM CUSTOMERS, LOANS
WHERE CUSTOMERS.C_ID = LOANS.C_ID
AND L_Date > '2024-12-31';
C_ID is in both tables, so it must be qualified with a table name. Dates in 'YYYY-MM-DD' form compare correctly. For the sample data this lists loans 1, 3, 4 and 5 (00003 David Xavier 60, 00001 Raj Malhotra 48, 00003 David Xavier 36, 00004 Damini Iyer 60).
(iv)(a)
SELECT * FROM LOANS
ORDER BY RoI DESC;
OR (iv)(b)
SELECT C_ID, AVG(Terms) FROM LOANS
GROUP BY C_ID;
GROUP BY C_ID makes one group per customer and AVG(Terms) averages the terms in each group (for 00003: (60 + 36) / 2 = 48).
© examsnet.com
Advertisements
Go to Question: