Mysql-asg 1 ques-Loan (1)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Practical Assignment #1 (SQL Commands)

(Based on one table)

1. Consider a database LOANS with the following table:


Table: Loan_Accounts
AccNo Cust_Name Loan_Amount Instalments Int_Rate Start_Date Interest
1 R. K. Gupta 300000 36 12.00 19-07-2009
2 S. P. Sharma 500000 48 10.00 22-03-2008
3 K. P. Jain 300000 36 NULL 08-03-2007
4 M. P. Yadav 800000 60 10.00 06-12-2008
5 S. P. Sinha 200000 36 12.50 03-01-2010
6 P. Sharma 700000 60 12.50 05-06-2008
7 K. S. Dhall 500000 48 NULL 05-03-2008

Write SQL commands for the tasks 1 to 35


Create Database and use it
1. Create the database LOANS.
2. Use the database LOANS.

Create Table / Insert Into


3. Create the table Loan_Accounts and insert tuples in it.

Simple Select
4. Display the details of all the loans.
5. Display the AccNo, Cust_Name, and Loan_Amount of all the loans.

Conditional Select using Where Clause


6. Display the details of all the loans with less than 40 instalments.
7. Display the AccNo and Loan_Amount of all the loans started before 01-04-2009.
8. Display the Int_Rate of all the loans started after 01-04-2009.

Using NULL
9. Display the details of all the loans whose rate of interest is NULL.
10. Display the details of all the loans whose rate of interest is not NULL.

Using DISTINCT Clause


11. Display the amounts of various loans from the table Loan_Accounts. A loan amount should appear
only once.
12. Display the number of instalments of various loans from the table Loan_Accounts. An instalment
should appear only once.

Using Logical Operators (NOT, AND, OR)


13. Display the details of all the loans started after 31-12-2008 for which the number of instalments are
more than 36.
14. Display the Cust_Name and Loan_Amount for all the loans which do not have number of
instalments 36.
15. Display the Cust_Name and Loan_Amount for all the loans for which the loan amount isless than
500000 or int_rate is more than 12.

Page 1 of 3
16. Display the details of all the loans which started in the year 2009.
17. Display the details of all the loans whose Loan_Amount is in the range 400000 to 500000.
18. Display the details of all the loans whose rate of interest is in the range 11% to 12%.

Using IN Operator
19. Display the Cust_Name and Loan_Amount for all the loans for which the number of instalments
are 24, 36, or 48. (Using IN operator)
20. Write an alternate way of writing the same query as in Q.19 without using IN.

Using BETWEEN Operator


21. Display the details of all the loans whose Loan_Amount is in the range 400000 to 500000. (Using
BETWEEN operator)
22. Display the details of all the loans whose rate of interest is in the range 11% to 12%. (Using
BETWEEN operator)
23. Write an alternate way of writing the same query as in Q.22 without using BETWEEN

Using LIKE Operator


24. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which theCust_Name
ends with 'Sharma'.
25. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which theCust_Name
ends with 'a'.
26. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which theCust_Name
contains 'a'
27. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which theCust_Name
does not contain 'P'.
28. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which theCust_Name
contains 'a' as the second last character.
29. Display the loan details of all customers whose name is exactly 5 characters long.

Using ORDER BY clause


30. Display the details of all the loans in the ascending order of their Loan_Amount.
31. Display the details of all the loans in the descending order of their Start_Date.
32. Display the details of all the loans in the ascending order of their Loan_Amount and within
Loan_Amount in the descending order of their Start_Date.

Using UPDATE, DELETE, ALTER TABLE


33. Put the interest rate 11.50% for all the loans for which interest rate is NULL.
34. Increase the interest rate by 0.5% for all the loans for which the loan amount is more than 400000.
35. For each loan replace Interest with (Loan_Amount*Int_Rate*Instalments)/ 12*100.
36. Change No of installments to 70 and Intr_rate as 12 for all loans more than 8000000.
37. Delete the records of all the loans whose start date is before 2007.
38. Delete the records of all the loans of 'K.P. Jain'
39. Assign Primary Key to column AccNo.
40. Add another column Category of type CHAR(1) in the Loan table.
41. Rename the column Instalments to Instl.
42. Delete the column interest
43. Delete all records from table Loan without deleting the table.
44. Delete all records from table Loan alongwith the table as well.
45. Delete all records from table Loan without deleting the table such that memory space is released.

Page 2 of 3
2. Create the table WORKER and add records as shown below. Write SQL commands
for the statements (a) to (g).
EMPNO ENAME JOB HIREDATE SAL COMM DEPTNO
8369 SMITH CLERK 1990-12-18 8000 NULL 20
8499 ANYA SALESMAN 1991-02-20 16000 500 30
8521 MAHADEVAN SALESMAN 1991-02-22 10000 300 30
8566 MOMIN MANAGER 1991-04-02 25000 NULL 10
8654 BINA ANALYST 1992-12-09 30000 NULL 20
8698 SHIAVNSH PRESIDENT 1991-11-18 50000 NULL 10
8882 SCOTT SALESMAN 1991-05-01 12000 1200 30

a. To display the details in ascending order of salary.


b. To display empno, empname in descending order of hiredate.
c. To display the details in ascending order of empno.
d. To display the sum of salary with heading ‘Sum of salary’.
e. To display the number of employees in each department number.
f. To display the number of employees in each department but number of employees
should be less than 3.
g. To display the sum of salary, average of salary, maximum and minimum salary of
each job title.

3. Create a table EMPLOYEE with the following data. Write SQL commands for the
statements (a) to (h).
Table: EMPLOYEE
No Name Salary Area Age Grade Dept
711 KESHAR 40000 WEST 45 C CIVIL
262 KIRTI 35000 SOUTH 38 A ELEC
693 KRIPPLE 60000 NORTH 52 B CIVIL
724 ARYAN 38000 NORTH 29 B CIVIL
705 SAMSON 42000 EAST 35 A COMP
606 BISWAL 29000 SOUTH 34 A MECH

a. To display the list of all employees in ascending order of salary.


b. To display the employee names in descending order of age.
c. To display the grade and number of employees in each grade.
d. To display the area and number of employees in each area.
e. To display the sum and average salary of the employees of grade ‘B’.
f. To display grade and maximum, minimum and average salary of each grade.
g. To display the sum, average, maximum and minimum of salary.
h. To display grade and the number of employees in each grade where the number of
employees are more than two.

Page 3 of 3

You might also like