My SQL Project
My SQL Project
Practical file
Informatics Practices
(Code No. - 065)
Session-2021-22
INDEX
S.N TITLE DATE PAG Teacher’s
o. E
Signature
NO
1 To create a database. 30|12|2021 8
23 Group by 30|12|2021 27
56 Average 30|12|2021 41
Q.6 To display student_id, name and marks of those students who are scoring
more than 50.
Select student_id, name, marks from student where marks>50;
Q.7 To find the average of marks from student table.
Select avg(marks) from student;
Q.8 To add a new column email in above table with appropriate datatypes.
Alter table student add(email varchar(50));
Q.9 To add the email id of each student in the previously created email column.
Update student set email=’ayush05@gmail.com’ where student_id=5;
Update student set email=’bhavesh05@gmail.com’ where student_id=10;
Update student set email=’charul05@gmail.com’ where student_id=15;
Update student set email=’divyansh04gmail.com’ where student_id=20;
Update student set email=’isha04@gmail.com’ where student_id=25;
Update student set email=’janvi04@gmail.com’ where student_id=30;
Update student set email=’khush05@gmail.com’ where student_id=35;
Update student set email=’lavanya04@gmail.com’ where student_id=40;
Update student set email=’mohit03@gmail.com’ where student_id=45;
Update student set email=’nikita03@gmail.com’ where student_id=55;
Q.10 To display the information of all the students whose name starts with
,AN’.
Select * from student where name like ‘AN%’;
Q.11 To display student_id, name,dob of those students who are born between
‘2005-01-01’ and ‘2005-12-31’.
Select Student_id, name, dob from student where dob>’2005-01-01’ and
dob<’2005-12-31’;
2) Maximum
Select max(marks) from student;
3) Sum
Select sum(marks) from student;
4) Average
Select avg(marks) from student;
III) MID
Select Substr(‘aBcdEfg’,-3);
IV) Length
Select length(‘aBcdEfg’);
VI) Right
Select right(‘aBcdEfg’,4);
VII) INSTR()
Select instr(‘aBcdEfg’,’c’);
VIII) LTTIM
Select ltrim(‘ aBcdEfg ‘);
IX) RTRIM
select Rtrim (‘ aBcdEfg ‘);
X) TRIM
select trim( leadimg ’a’ from ‘aBcdEfg’);
iii) MonthSelect
month(now());
iv) Monthname()select
monthname(now())
;
v) year()select
year(now());
vi) Day
Select day(‘2021-07-10’);
vii) Daynameselect
dayname(‘2021-
07-10’);
Q.22) Write a SQL function which will perform the following operations.
i) To display the the name of the month of the current date. Select
monthname(now());
iv)select instr(‘name’,’fname’);
Q.25) Write a command for using group by with order by. select distinct(class),
section from student group by class order by section;
Q. 26)Command for using group by and having clause with where clause.
Select avg(marks), class from student where gender="M" group by class
having avg(marks)>68;
Q.27) Write a command to remove primary key.Alter table
student drop primary key;
Q.36) Write a command to display the deatails of all loans with less than 40
installments.
Select * from loan where instal<40;
Q.37) Write a command to display the details of all the loan whose rate of
interest is null.
Select * from loan where int_rate is null;
Q.38) Write a command to display the amount of various loans from the table
loans, a loan amount should only appear once.
Select distinct(loan_amt)from loan;
Q.39) Write a command to display the customer name, loan amount for all the
loans which do not have number of instalments 36.
Select acc_name, loan_amt from loan where instal!=36;
Q.40) Write a command the details of all the loans whose loan amount is in the
rate of 400000 and 500000.
Select * from loan where loan_amt between 400000 and 500000;
Q.41) Write a command to display the account number, customer name and
loan amount of all the loans for which customer name is “sharma”.
Select acc_no, acc_name, loan_amt from loan where acc_name like
“%sharma%”;
Q.42) Write a command to display the details of all loans in the ascending
order of their loan amount
Select * from loan order by loan_amt desc;
Q.43) Write a command to put the interest rate 11.50% for all the loans for
which the interest rate is null.
Update loan set int_rate=11.50 where int_rate is null;
Q.44) Display the details of all the loans whose instalment is below 40 and
loan amont above 250000.
Select * from loan where instal<40 and loan_amt >250000;
Q.45) Write a command to delete the details of all loans whose start date is
before 2008
Delete from loan where year(start_date)<2008;
Q.46) Write a command to add a column category of type char(1) in the table
loan.
Alter table loan add category char(1);
Q.47) Display the maximum loan amount whose interest rate is 12%.
Select max(loan_amt) from loan where int_rate=12;
Q.48) Find the average instalments.
Select avg(instal) from loan;
Q.50) To count the total number of customers whose loan started after
2008.
Select count(start_date) from loan where year(start_date)>2008;
Q.51) Write a command to create given table sports and insert records in
it.
Create table sports( adm_no Int(11) primary key, game varchar(50),
coach_name varchar(60), Grade char(1));
Q.52) Display the lowest and the highest class from the table student.
Select Min(class),Max(class) from student;
Q. 53)Display the number of students in each class from the table student.
Select count(class), class from student group by class;
Q.54) Display the number of students with each coach.
Select count(*), coach name from sports group by coach_name;
Q.55) Create table item and bill and insert the given records in it.
Create table item(icode int(11) primary key, name varchar(50), category
varchar(60), rate int(11));
Create table bill(bill_no int(11) primary key, date Date, icode int(11) , quantity
int(11));
Q.58) Consider the following table given below and answer the following
questions.
No Name Salary Zone Age Grade Dept
.
1 Mukul 30000 West 28 A 10
2 Kritika 35000 Centre 30 A 10
3 Naveen 32000 West 40 NULL 20
4 Uday 38000 North 38 C 30
2) Display the details of all the employees who are getting a salary of more
than 35000 in the department 30.
Select * from employee where salary>35000 and dept=30;
3) Display the name and salary of all the employees who are working neither
in west zone nor in center zone.
Select name, salary from employee where zone!= “west” and zone! =“center”;
6) Display the details of all the employees in the ascending order of their
salaries.
Select * from employee order by salary;
7) Display the name, salary and age of all the employees whose name starts
with “a”.
Select name, salary, age from employee where name like “a%”;
Q.59) Consider the table teacher and answer the following questions.
Create table Teacher( No int(11) primary key, Name Varchar(50),Age int(11),
Department Varchar(40), DATEOFJOIN DATE, Salary decimal(10,2), Sex
Char(1));
1)
Display the name and salary of male teachers in the math department.
Select name, salary from teacher where sex=”M” and department=”maths”;
2)Display the no of teachers in each department.
Select count(*), department from teacher group by department;
3)Display the details of all teachers who are getting salary less than 25000 of
computer department.
Select * from teacher where salary<25000 and department = “computer”;
4)Display the total salary and the average salary of teachers of history
department.
Select avg(salary), Sum(salary) from teacher where department=”history”;
5)Display the name, age and department of teachers whose name contains H as
the second character.
Select name, age, department from teacher where name like”_h%”;
Q.60) Consider the table teacher and answer the questions given below.
1) Display the details of female teachers of history department.
Select * from teacher where Sex=”F” and Department=”History”;
2) Display the name and Date of join of teachers according to their date of
join.
Select name, DATEOFJOIN from teacher group by DATEOFJOIN;