You are on page 1of 30

ISM LAB FILE

Ques 18) Retrieve all rows where name field contains the
word ‘Priya’ Ans) Select* from abhaykrishan_customer where
Fname like ‘Pr_ya%’

Ques 19) Retrieve all rows where city is New Delhi, Seoul or Manila.
Ans) Select* from abhaykrishan_customer where CITY in (‘New Delhi’, ‘Punjab
or Banglore’)

ENROLLMENTNO. P a g e 20 | 71
12224401719
ISM LAB FILE

Ques 20) Rename the table customer


to abhaykrishan_custromer1
Ans) Steps:
• Rename abhaykrishan_customer to abhaykrishan_customer1
• Select* from abhaykrishan_customer1

Ques 21) Delete all those rows of customers who stay in


Gangnam Ans) Steps:
• Delete abhaykrishan_customer1 where City= ‘Banglore’
• Select* from abhaykrishan_customer1

ENROLLMENTNO. P a g e 21 | 71
12224401719
ISM LAB FILE

Ques 22) Delete those customers who do not have


Pin Code. Ans) Steps:
• Delete from abhaykrishan_customer1 where pin is null
• Select* from abhaykrishan_customer1

Ques 23) Rename column city to


address. Ans) Steps:
• Alter table abhaykrishan_customer1 rename column city to address
• Select* from abhaykrishan_customer1

ENROLLMENTNO. P a g e 22 | 71
12224401719
ISM LAB FILE

Ques 24) Delete the customers who do not belong


to New DElhi.
Ans) Steps:
• Delete from abhaykrishan_customer1 where not address= ‘New Delhi’
• Select* from abhaykrishan_customer1

ASSIGNMENT 3
Ques 1) Create table employee.
Ans) Steps:
• Create table abhaykrishan_employee1(Empid number(3), Fname
char(10), Lname varchar(10), Bdate date, Address varchar(10), Gender
char(6), Salary number(10), Depno number(5))
• Desc abhaykrishan_employee1

ENROLLMENTNO. P a g e 23 | 107
12624401719
ISM LAB FILE

Ques 2) Insert 5 records in employee


table. Ans) Steps:
• Insert into abhaykrishan_employee1
values(101,'Megha','Sharma',’31/Jul/1995’,’Hari
Nagar’,’Female’, 25000,001)
• Insert into abhaykrishan_employee1
values(102,'Sakshi','Gupta',’09/Feb/1995’,’Moti Bagh’,’Female’,
30000,002)
• Insert into abhaykrishan_employee1
values(103,'Arush','Sharma',’12/Jan/1998’,’Janak Puri’,’Male’,
35000,003)
• Insert into abhaykrishan_employee1
values(104,'Priya','Kapoor',’01/Mar/1998’,’Janak Puri’,’Female’,
40000,004)
• Insert into abhaykrishan_employee1
values(105,'Harshdeep','Kaur',’26/Aug/1992’,’Kalka Ji’,’Male’,
50000,005)
• Select* from abhaykrishan_employee1

ENROLLMENTNO. P a g e 24 | 107
12624401719
ISM LAB FILE

Ques 3) List name of all employees who work in


Dept No. 5. Ans) Select Fname, Lname from
abhaykrishan_employee1 where Deptno= 5

Ques 4) Find names and salary of all the employees sorted


according to salary. Ans) Select Fname, Lname, salary from
abhaykrishan_employee1 order by salary

ENROLLMENTNO. P a g e 25 | 107
12624401719
ISM LAB FILE

Ques 5) List names of employees having salary between 30,000 and 50,000
Ans) Select Fname, Lname, salary from Shefali_emp where salary>=30000 and
salary<=50000

Ques 6) List name of employees who live in Janak Puri


Ans) Select Fname, Lname, Address from abhaykrishan_employee1 where
address= ‘Janak Puri’

ENROLLMENTNO. P a g e 26 | 107
12624401719
ISM LAB FILE

Ques 7) List name of all the female employees.


Ans) Select Fname, Lname, Gender from abhaykrishan_employee1 where
Gender= ‘Female’

Ques 8) List name of those employees whose bdate is before 2 Nov


1999 Ans) Select Fname, Lname, Bdate from
abhaykrishan_employee1 where Bdate<2/Nov/1996

ENROLLMENTNO. P a g e 27 | 107
12624401719
ISM LAB FILE

Ques 9) List all employees whose FName is “Megha” and LName is


“Sharma”

Ans) Select Fname, Lname from abhaykrishan_emp where Fname= ‘Megha’ and
Lname= ‘Sharma’

Ques 10) Rename the column address


to city. Ans) Steps:
• Alter table abhaykrishan_employee1 rename column address to city
• Select* from abhaykrishan_employee1

ENROLLMENTNO. P a g e 28 | 107
12624401719
ISM LAB FILE

Ques 11) Sort the employees in descending order


of city. Ans) Select* from
abhaykrishan_employee1 order by city desc

Ques 12) Update the person named “Priya” to


“Megha” Ans) Steps:
• Update abhaykrishan_employee1 set Fname= “Megha” where Fname=
“Priya”
• Select* from abhaykrishan_employee1

ENROLLMENTNO. P a g e 29 | 107
12624401719
ISM LAB FILE

Ques 13) Update city of EmpID 101 to Jaipur.


Ans) Steps:
• Update abhaykrishan_employee1 set city= ‘Jaipur’ where EmpID= 101
• Select* from abhaykrishan_employee1

Ques 14) Delete record of


EmpID 102 Ans) Steps:
• Delete from abhaykrishan_employee1 where EmpID= 102
• Select* from abhaykrishan_employee1

ENROLLMENTNO. P a g e 30 | 107
12624401719
ISM LAB FILE

Ques 15) Display those employees where salary is not equal to 20,000
Ans) Select* from abhaykrishan_emp where salary<>20000

ASSIGNMENT 4
Ques 1) Create table
employee. Ans) Steps:
• Create table abhaykrishan_employee(EmpNo number(3), Ename char(20)
not null, Salary number(10) not null, Commission number(4), Job
char(20), Deptno number(3))
• Desc abhaykrishan_employee

ENROLLMENTNO. P a g e 31 | 107
12624401719
ISM LAB FILE

Ques 2) Insert 5 records in employee


table. Ans) Steps:
• Insert into abhaykrishan_employee3
values(102,'Nisha',55000,500,’Engineer’,7)
• Insert into abhaykrishan_employee3
values(103,'Neha',60000,’Manager’,10)
• Insert into abhaykrishan_employee3
values(104,'Ashish',50000,1000,’Supervisor’,8)
• Insert into abhaykrishan_employee3
values(105,'Nishant',70000,2000,’Assistant Manager’,9)
• Insert into abhaykrishan_employee3
values(106,'Nikhil',7000,200,’Clerk’,10)
• Select* from abhaykrishan_employee3

Ques 3) Find average and total salaries of all


employees. Ans) Select Avg(salary), Sum(salary)
from abhaykrishan_employee

ENROLLMENTNO. P a g e 32 | 107
12624401719
ISM LAB FILE

Ques 4) Find average and total salaries of each employee.

Ans) Select Avg(salary), Sum(salary) from abhaykrishan_employee3 group by


Job

Ques 5) Find minimum salary of Manager.


Ans) Select MIN(salary) from abhaykrishan_employee3 where Job= ’Manager’
ENROLLMENTNO. P a g e 33 | 107
12624401719
ISM LAB FILE

Ques 6) Find the maximum salary of Manager.


Ans) Select MAX(salary) from abhaykrishan_employee3 where Job= ’Manager’

Ques 7) How many employees are Managers.

Ans) Select COUNT(EmpID) from abhaykrishan_employee3 where Job=


‘Manager’

ENROLLMENTNO. P a g e 34 | 107
12624401719
ISM LAB FILE

Ques 8) Add 50% salary to salary column and


name it HRA Ans) Steps:
• Select EmpNo, Ename, Salary+(salary*0.5) as HRA from
abhaykrishan_employee3
• Select* from abhaykrishan_employee3

Ques 9) Count the total no. of employees.

ENROLLMENTNO. P a g e 35 | 107
12624401719
ISM LAB FILE

Ans) Select COUNT(EMPNO) from


abhaykrishan_employee3

Ques 10) Count the no. of department of available.


Ans) Select COUNT(distinct(DEPTNO)) from abhaykrishan_employee3

Ques 11) Count the no. of employees in each department


Ans) Select COUNT(distinct(EmpNO) from abhaykrishan_employee3 group by
DEPTNO
ENROLLMENTNO. P a g e 36 | 107
12624401719
ISM LAB FILE

Ques 12) Update the commission to 10% of salary for all the employees
having salary greater than 50000
Ans) Steps:

• Update abhaykrishan_employee3 set commission=salary*0.1 where


salary>50000
• Select* from abhaykrishan_employee3

ENROLLMENTNO. P a g e 37 | 107
12624401719
ISM LAB FILE

Ques 13) Find the name of lowest paid employee for each
manager. Ans) Select MIN(salary) from
abhaykrishan_employee3 group by DEPTNO

Ques 14) Update the salaries of all employees in department 10 by


hiking it by 15%.
Ans) Steps:
• Update abhaykrishan_employee3 set salary=salary*1.15 where Deptno=10
• Select* from abhaykrishan_employee3

ENROLLMENTNO. P a g e 38 | 107
12624401719
ISM LAB FILE

Ques 15) Find the difference between highest and lowest salaries
Ans) Select MAX(salary)-MIN(salary) from abhaykrishan_employee3

Ques 16) List average salary for all the depts which have more than 2 People.
Ans) Select Avg(salary), Depno from abhaykrishan_employee3 group by Depno
having COUNT(distinct Empno)>1

ENROLLMENTNO. P a g e 39 | 107
12624401719
ISM LAB FILE

Ques 17) List jobs of all the employees where maximum salary is more
than 40000 Ans) Select JOB from abhaykrishan_employee3 group by
JOB having max(SALARY)>5000

Ques 18) List jobs and number of employees in each JOB. The result should
be in decreasing order.
Ans) Select JOB,count(distinct (empno)) from abhaykrishan_employee3 group
by JOB order by COUNT(empno) desc

ENROLLMENTNO. P a g e 40 | 107
12624401719
ISM LAB FILE

Ques 19) List average salary of each desg excluding managers.


Ans) Select Avg(salary) from abhaykrishan_employee3 where JOB<>’Manager’
group by JOB

Ques 20) List total, Max, Min, Average salary of employees job wise.
Ans) Select JOB,Sum(salary), Avg(salary), Max(salary), Min(salary) from
abhaykrishan_employee3 where DEPNO=10 group by JOB having
avg(SALARY)>=10000

ENROLLMENTNO. P a g e 41 | 107
12624401719
ISM LAB FILE

ASSIGNMENT-5
Question. (1) create table course (CCODE number(5) primary key,CNAME
varchar(10) unique,FEE number(5))

(2) create table student(ROLLNO number(5) primary key,SNAME


varchar(20),DOB date(not null),CCODE number(5), YEAR OF ADMISSION
number(5))

ENROLLMENTNO. P a g e 42 | 107
12624401719
ISM LAB FILE

(3) insert into course values(101, ‘Python’, 6000)


insert into course values(102, ‘C++’, 7000)
insert into course values(103, ‘Java’, 8000)

(3)1. insert into student values(1, ‘Ram’, 23-SEP-1992, 101, 2019)


insert into student values(1, ‘Shyam’, 12-NOV-1995, 101, 2020)
insert into student values(1, ‘Mohan’, 05-JAN-1996, 101, 2021)
insert into student values(1, ‘Ramesh’, 05-JAN-1996,-, 2021)

ENROLLMENTNO. P a g e 43 | 107
12624401719
ISM LAB FILE

(4) select (sysdate-DOB)/365 from student

(5) select * from student,course where student.ccode=course.ccode

ENROLLMENTNO. P a g e 44 | 107
12624401719
ISM LAB FILE

(6) select * from student,course where student.ccode=course.ccode and cname=


‘Python’

(7) select sname from student where year_of_admission in(select


year_of_admission from student group by year_of_admission having
count(year_of_admission)>1)

ENROLLMENTNO. P a g e 45 | 107
12624401719
ISM LAB FILE

(8) select count(*) from student where year_of_admission in(select


year_of_admission from student group by year_of_admission having
count(year_of_admission)>1)

(9) select * from student where ccode in(select ccode from student where
rollno=1) and rollno!=1

ENROLLMENTNO. P a g e 46 | 107
12624401719
ISM LAB FILE

(10) select sname from student,course where fee=(select MAX(Fee) from course)
and student,course=course.ccode

ASSIGNMENT-6
Question (1) Create table hotel and insert 3 records for the following attributes:-
Hotelno(primary key), Hotelname, city

ENROLLMENTNO. P a g e 47 | 107
12624401719
ISM LAB FILE

(2) Create table Room and insert 3 records into table:- Roomno(primary
key),hotelno(foreign key),type of room,price

(3) Create table guest and insert 3 records into table:- Guestno(primary
key),gname,gaddress

ENROLLMENTNO. P a g e 48 | 107
12624401719
ISM LAB FILE

(4) Create table booking and insert 3 records for the following fields:- Hotelno-
foreign key),guestno(foreign key),datefrom,dateto,roomno

(5) Find average price of a room

ENROLLMENTNO. P a g e 49 | 107
12624401719

You might also like