Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views6 pages

SQL Function and Join Query Question For Practical File

The document outlines a series of SQL tasks and queries related to various tables such as Loan_Accounts, Grocer, Charity, items, Vehicle, and Employee. It includes instructions for creating databases, inserting data, and performing queries to retrieve specific information. Additionally, it specifies the expected outputs for certain SQL commands.

Uploaded by

sharmashweta7819
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

SQL Function and Join Query Question For Practical File

The document outlines a series of SQL tasks and queries related to various tables such as Loan_Accounts, Grocer, Charity, items, Vehicle, and Employee. It includes instructions for creating databases, inserting data, and performing queries to retrieve specific information. Additionally, it specifies the expected outputs for certain SQL commands.

Uploaded by

sharmashweta7819
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Q1Consider a database LOANS with the following table:

Table: Loan_Accounts
AccNo Cust_Name Loan_Amount Instalments Int_Rate Start_Date
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 and write the output for the SQL com to 40:
1Create the database LOANS.

2 Use the database LOANS. ,

3 Create the table Loan_Accounts and insert tuples in it.

4. Display the details of all the loans


5.Display the accno , custname, loan_amount of all the loans.
6. Display the details of all the loans whose rate of Interest is not NULL.
7. Display the number of instalments of various loans from the table Loan_Accounts. An Instalment should
appear only once..
8. Display the details of all the loans started after 31-12-2008 for which the number of instalments are
more than 36.
9. Display the Cust_Name and Loan_Amount for all the loans which do not have number of instalments 36.
Display details of all the loans whose loan amount is in the range 400000 and 500000.
10. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name ends with
'Sharma'.
11. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name contains
'a'
12. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name contains
'a' as the second last character.
13. Display the details of all the loans in the descending order of their Start_Date
14. Put the interest rate 11.50% for all the loans for which interest rate is null
15. Delete records of all the loans of K.P.Jain
16.Add another column category of type char (1) in loans table

Find the Output of the following queries

1
17. SELECT cust name, LENGTH(Cust_Name), LCASE(Cust_Name), UCASE(Cust_Name) FROM Loan
Accounts WHERE Int_Rate < 11.00;

18. SELECT LEFT (Cust_Name, 3), Right(Cust_Name, 3), SUBSTR(Cust_Name, 1, 3) FROM Loan Accounts
WHERE Int_Rate > 10.00;
19. SELECT RIGHT (Cust_Name, 3), SUBSTR(Cust_Name, 5) FROM Loan_Accounts;
20. SELECT DAYNAME(Start_Date) FROM Loan_Accounts;
21. SELECT ROUND(Int_Rate 110/100, 2) FROM Loan_Account WHERE Int_Rate > 10;
Write the output produced by the following SQL commands:

21. SELECT POW(4,3), POW(3,4);


22. SELECT ROUND (543.5694,2), ROUND (543.5694), ROUND(543.5694,-1);
23. SELECT TRUNCATE (543.5694,2), TRUNCATE (543.5694,-1);
24. SELECT LENGTH("Prof. M. L. Sharma");
25. SELECT CONCAT("SHEIKH", "HAROON") "FULL NAME";
26. SELECT YEAR(CURDATE()), MONTH(CURDATE()), DAY (CURDATE());
27. SELECT DAYOFYEAR(CURDATE()), DAYOFMONTH(CURDATE()), DAYNAME (CURDATE());
28. SELECT LEFT("Unicode", 3), RIGHT("Unicode", 4);
29. SELECT INSTR("UNICODE","CO"), INSTR("UNICODE", "CD");
30. SELECT MID("Informatics", 3, 4), SUBSTR("Practices”3);
Q2
Table Grocer:
Itemi d Itemnam Unitprice(pe r kg) Quantity(kg Date_purchase d
e )

1 Rice 52.50 80 2023/02/01

2 Wheat 25.40 50 2024/03/09

3 Corn 50.80 100 2024/01/11

4 Semolina 28.90 53 2024/01/15

Write SQL query for following:

1. Display item name, unit price and month name for all the items

2. Display first two characters of item name along with month(in number)when it was purchased for
all the items.

3. Display the total amount Predict the output:


Select item name date_purchased from Grocer where quantity
= (select max(quantity) from grocer);
Q3

2
Table Charity Write SQL query for following:
Pi d Lname Fname Address City Contribut ion

1 Bindra Jaspreet 5B,Gomti nagar Lucknow 3500.50

2 Rana Monica 21A,Band Mumbai 2768.90


ra

3 Singh Jatinder 8,Punjabi Delhi 2000.56


Bagh

4 Krishna Vineeta A75,Adar sh


nagar

• Display first name in lower case

• Display last names of people of Mumbai city in uppercase

• Display person id along with first three characters of fname

• Display fname, password( fname concated with length of address and person id) for those who
lives in Mumbai

• Display position of ‘a ‘ in last name

• Display last charcter of city and 3 to 6 character of address

• Display length of address

• Display last name of those who have ‘at’ in second or third position in their first names
Q5
Table ‘ items’:
Icode Name Category rate

1001 Masala dosa South indian 60

1002 Vada sambhar South indian 40

2001 Chow mein chinese 40

2002 Dimsum chinese 80

3
3001 Pizza italian 160

2003 Soup Chinese 60

Table ‘bills’
Billno Date Icode qty

1 2010/04/01 1002 2

1 2010/04/01 2003 1

2 2010/04/01 3001 4

2 2010/04/01 1001 3

3 2010/04/02 2002 4

3 2010/04/02 1002 3

3 2010/04/02 3001 2

4 2010/04/6 1001 8

1. Display average rate of south indian items


2.Display the number of items in each category
3.Display the total quantity sold for each item
4.Display total quantity of each item sold but don’t display this data for the items whose total quantity
sold is less than 3

5. Display details of bill records along with Name of each corresponding item
6. Display the details of the bill records for which the item is Dosa
7. Display the bill records for each Italian item sold
8.Display the total value of items sold for each bill
Q6
Table Vehicle
Field Type Null Key default

Regno Char(15) No Pri

4
Regdate Date Yes Null

Owner Varchar(20) No Mr.X

Address Varchar(30) Yes Jaipur

Sample data: Rj4856,2019/08/18,Mr.Grish Bhandari,Gopal Bari ,Jaipur


Table offence:

Field Type Null Key default

Offence_code Int(3) No Pri

Descr Varchar(20) No Minor driving

Challan amt Float(11,2) Yes 500.00

Sample data: 101, driving without seatbelt,1000.50 Table challan:


Field Type Null Key default

challanno int No Pri

chdate Date Yes Null

Regno Char(15) yes foreign Null

Off_code Int(3) Yes foreign Null

Sample data: 1,2024/08/30,Rj4856,101

1. Display the date of first registration and last registration from table vehicle
2. Display the number of challans issued on each date
3. Display the total number of vehicle for which the 1st and 2nd character are ‘UP’
4. Display the total value of challans issued for which the off desc id “drink and drive”
5. Display the regno of all vehicles which have been challaned more than once
6. Display details of each challan along with vehicle details,offence description and challan amount
Q7
Table Employee

No Name Salary Zone Age Grade dept

5
1 Mukul 30000 West 28 A 10

2 Kritika 3600 Centre 30 A 10

3 Naveen 3200 West 40 Null 20

4 Uday 38000 North 38 C 30

5 Nupur 37000 East 26 Null 20

6 Moksh 32000 South 29 B 30

Table Department
Dept Dname Minsal maxsal HOD

10 Sales 2500 32000 1

20 Finance 3000 40000 5

30 Admin 2500 50000 4

Add foreign key


Display the details of all the employees who work in sales department
Display the salary , zone and grade of all the employees whose HOD is nupur
Display the name and department name of all employees
Display the name of department and the name of the corresponding HOD for all the departments

*****

You might also like