Anda di halaman 1dari 6

section 1:(30 min) a) List the names of analysts and salesmen.

: select ename from emp where job in('ANALYST','SALESMAN'); b) List details of employees who have joined before 30 Sep 81. : select * from emp where hiredate<'09/30/1981' c) List names of employees who are not managers. : select ename from emp where job !='MANAGER'; d) List the names of employees whose employee numbers are 7369, 7521, 7839, 7934, 7788. : select ename from emp where empno in(7369,7521,7839); e) List employees not belonging to department 30, 40, or 10. : select ename from emp where deptno not in(30,40,10); f) List employee names for those who have joined between 30 June and 31 Dec. 81. : select ename from emp where hiredate between '06/30/1981' and '12/31/1981'; g) List the different designations in the company. : select distinct(job) from emp; h) List the names of employees who are not eligible for commission. : select ename from emp where comm is null; i) List the name and designation of the employee who does not report to anybody. : select ename,job from emp where mgr is null; j) List the employees not assigned to any department. : select ename from emp where deptno is null; k) List the employees who are eligible for commission. : select ename from emp where comm is not null; l) List employees whose names either start or end with S. : select ename from emp where ename like 'S%' or ename like '%S'; m) List names of employees whose names have i as the second character. : select ename from emp where ename like '_I%'; n) List the number of employees working with the company. o) List the number of designations available in the EMP table. : select count(distinct(job)) from emp;

p) List the total salaries paid to the employees. : select sum(sal+nvl(comm,0)) from emp; q) List the maximum, minimum and average salary in the company. : select max(sal+nvl(comm,0)),min(sal+nvl(comm,0)),avg(sal+nvl(comm,0)) from emp; r) List the maximum salary paid to a salesman. : select max(sal) from emp where job='SALESMAN';

section:-2 (40 min) a) List the number of employees and average salary for employees in department 20. : select ename,(select round(avg(sal),2) from emp) from emp where deptno=20; b) List name, salary and PF amount of all employees. (PF is calculated as 10% of basic salary) b) List names of employees who are more than 25 years old in the company. : select ename from emp where round((sysdate-hiredate)/12)>25; c) List the employee details in the ascending order of their basic salary. : select ename,sal from emp order by sal; d) List the employee name and hire date in the descending order of the hire date. : select ename,hiredate from emp order by hiredate desc; f) List employee name, salary, PF, HRA, DA and gross; order the results in the ascending order of gross. HRA is 50% of the salary and DA is 30% of the salary. g) List the department numbers and number of employees in each department. : select deptno,count(deptno) from emp group by deptno; h) List the department number and total salary payable in each department. : select deptno,sum(sal+nvl(comm,0)) from emp group by deptno; List the jobs and number of employees in each job. The result should be in the descending order of the number of employees. : select job,count(empno) from emp group by job order by count(empno) desc; j) List the total salary, maximum and minimum salary and average salary of the employees jobwise. i)

: select job,sum(sal),max(sal),min(sal),avg(sal) from emp group by job; k) List the total salary, maximum and minimum salary and average salary of the employees, for department 20. : select sum(sal),max(sal),min(sal),avg(sal) from emp where deptno=20 group by deptno (or having deptno=20); l) List the average salary of the employees job wise, for department 20 and display only those rows having an average salary > 1000 : select avg(sal) from emp where deptno=20 group by job,deptno having avg(sal)>1000;

section:-3 Problem Description: Create the following tables with the help of the description given below and solve the SQL queries. Trainer table Column Name TrainerID TrainerName EmailID Phone

Data Type Number(2) Varchar2(10) Varchar2(10) Varchar2(10)

Description Primary Key Not Null Unique Can be null

Trainer TrainerID 1 2 3 4 5 Course_Details

TrainerName Abraham Boyce Camilla Davis Elsa

EmailID t1@i.com t2@i.com t3@i.com t4@i.com t5@i.com

Phone 9844499901 9844499902 9844499903 9844499904 9844499405

Column Name CourseID CourseName Course_Details CourseID GPF GDB ODB OVB JJA JJE

Data Type Char(3) Varchar2(30)

Description Primary Key Not Null

CourseName Programming Fundamentals Relational Database Management System Oracle 9i Visual Basic Java Java JEE1

Batch_Schedule Column Name BatchName CourseID Start_Date End_Date = Start_Date Data Type Description Varchar2(8) PK Char(3) FK/PK Date Not Null Date Not Null,End_Date should be >

Batch_Schedule

BatchName Batch1 Batch1 Batch1 Batch1 Batch2 Batch3 Batch3

CourseID GPF GDB ODB OVB GPF GPF JJA

Start_Date 10-Jan-2008 21-Jan-2008 01-Feb-2008

End_Date 20-Jan-2008 31-Jan-2008 20-Feb-2008

21-Feb-2008 28-Feb-2008 10-Jan-2008 21-Jan-2008 20-Jan-2008 01-Feb-2008

02-Feb-2008 08-Feb-2008

FeedBack Column Name TrainerID CourseID BatchName FBRate Data Type Number(2) Char(3) Varchar2(8) Number(3,2 Description FK PK FK Not Null,FBRate should be between 0 and 5.

FeedBack TrainerID 1 2 3 4 5 1 3 CourseID GPF GDB ODB OVB GPF GPF JJA BatchName Batch1 Batch1 Batch1 Batch1 Batch2 Batch3 Batch3 FBRate 4.18 4.65 4.51 4.68 4.28 4.28 4.32

Perform the following queries: a) List the TrainerName, CourseID, BatchName and FBRate of all the Trainers,who have handled the sessions. (Hint: TrainerIDs which are present in the Feedback Table) b) List the CourseName and the FBRate of each course. c) List the TrainerName,CourseName, BatchName and FBRate of all the handled courses. The output should be <TrainerName> <CourseName><BatchName><FBRate> d) List the name of trainers who have handled more than one course. e) List the TrainerId, name of trainers, who have average FBRate > 4.3. f) List the TrainerId, name of trainers, course names and the number of times each course has been handled.

g) List the batch name coursed and start date of courses starting on the same date. (Hint: Use concept of Self Join) h) Get the course Name and trainer Name for each batch as on 15 Jan 2008, only for batches which are in progress. i) List the Course Name and average FBRate the course. Also print the CourseName even if the Feedback is not available for that course. (Hint: use concept of Outer Join)

j) List the CourseID which has the highest average feedback. k) List the TrainerID , CourseID and CourseName of all the courses which are taught by the trainer. Also print the CourseId and CourseName of all the courses, which is not been taught by any trainer. (Hint: use concept of Outer Join)

Anda mungkin juga menyukai