ASSIGNMENT-1

1. List all the employees who have at least one person reporting to them. Ans: select ename from emp where empno in (select mgr from emp)

2. List the employee details if and only if more than 10 employees are present in department no 10. Ans: select ename from emp where empno in (select empno from emp where deptno='10' group by empno
having count(empno)>=1)

3. List the name of the employees with their immediate higher authority. Ans: select e1.ename,e2.ename from emp e1 join emp e2 on e1.mgr=e2.empno

4. List all the employees who do not manage any one. Ans: select ename from emp where empno not in (select mgr from emp group by mgr)

5. List the employee details whose salary is greater than the lowest salary of an employee belonging to deptno 20. ans: select *from EMP where SAL>(select MIN(SAL)from EMP where DEPTNO=20 )

6. List the details of the employee earning more than the highest paid manager. Ans: select * from EMP where sal> (select MAX(SAL) from EMP where JOB='MANAGER' )

7. List the highest salary paid for each job. Ans: select max(SAL),JOB from EMP group by JOB

8. Find the most recently hired employee in each department. Ans: select ename from emp where hiredate in (select max(hiredate) from emp group by deptno)

Ans: select case when hiredate in (select max(hiredate) from emp) then ename + '*' else ename end from emp 12.Which department has the highest annual remuneration bill? Ans: select top 1 sum(sal+comm) from emp group by deptno order by sum(sal+comm) desc 11.avg(SAL) as salary from EMP group by deptno) a join emp b on a. select empno. which are inserted.salary from (select DEPTNO.deptno.sal.a.Write a query to display a ‘*’ against the row of the most recently hired employee. Ans select max(total) from (select year(hiredate) as years. In which year did most people join the company? Display the year and the number of employees.count(empno) from emp group by empno having count(empno)>1 15.b.count(hiredate) as total from emp group by year(hiredate)) f 10. that already exist) in the EMP table.9. Select min(sal) from emp where sal in (select top 4 sal from emp order by sal desc) Ans: 14.salary 13.deptno and b.Find the nth maximum salary. select ename +' has '+ cast(year(getdate())-year(hiredate) as varchar)+' years and '+ cast(month(getdate())month(hiredate) as varchar)+' months of experience' from emp . Ans: select b.Write a correlated sub-query to list out the employees who earn more than the average salary of their department.Select the duplicate records (Records.sal>a.deptno=b.Write a query to list the length of service of the employees (of the form n years and m months).

Create a table named dept1 with did as number(4) and name varchar2(30) create table dept1( did number(4).'AAA') insert into dept1 values(0222.'N22'.'N11'.. 5.'EEE') insert into dept1 values(0666. 3. 4. name varchar2(30)). Make that manager_name as varchar2(30) alter table dept1 modify(manager_name varchar2(30)).'N66'. 6.'N555'. Oh!! U forgot to make that did as pk do it now alter table dept1 add(primary key(did)).U r manager wants that every name in dept1 table will be starting with N so add a check constraint alter table dept1 add(check(name like'N%')) Now U want to add a new column as manager_name as varchar2(5) alter table dept1 add(manager_name varchar2(5)). Insert the following data Did Name Manager_name 111 n11 AAA 222 n22 BBB 333 n33 CCC 444 n44 DDD 555 n555 EEE 666 n66 FFF 777 n77 GGG insert into dept1 values(0111.'CCC') insert into dept1 values(0444. 2.'N44'.'DDD') insert into dept1 values(0555.'BBB') insert into dept1 values(0333.ASSIGNMENT-2 1. Check that did is not null or not desc dept1 Not again. 7.'FFF') .'N33'.

10. ename varchar2(10).8. 9. Getting this error ORA/02267:Column type incompatible with referenced column type?Change the data type make emp1 of did and dept1 of did same data type alter table emp1 modify(did varchar2(30)).'BBB'. Now add the foreign key constraint ALTER TABLE emp1 ADD CONSTRAINT fk_PerOrders FOREIGN KEY(did) REFERENCES dept1 Insert the following data set into emp1 Emp id Ename Did 111 AAA 111 222 BBB 222 333 CCC 333 444 DDD 444 555 EEE 555 insert into emp1 values(111.222) insert into emp1 values(333. did varchar2(2)). 12.'AAA'. 11.did varchar2(2)) create table emp1( empid number(3) primary key.'N77'. 13. Create a table as emp1(empid number(3) primary key.'GGG') U made a mistake see n555 that should be n55 update dept1 set name='N55' where name='N555' We do not need that record with did=777 delete from dept1 where did=777. ename varchar2(10). insert into dept1 values(0777.333) . 14.'CCC'.111) insert into emp1 values(222. Now add a foreign key reference with dept1 of did to emp1 of did ALTER TABLE EMP1 ADD (FOREIGN KEY(DID) REFERENCES DEPT1).

.15.DEPT1 D WHERE D.NAME FROM EMP1 E.DID=E.DID.'EEE'. 16.555) Show me the enames and corresponding dept names SELECT E.DEPT1 D WHERE D.DID=E.DEPT1 D WHERE D. 17.NAME FROM EMP1 E.444) insert into emp1 values(555. insert into emp1 values(444.ENAME.DID.ENAME.DID.D.MANAGER_NAME FROM EMP1 E.'DDD'.DID=E. Show me all the dept names And matching dept Employees SELECT E.ENAME.D. I want all the employee name with manager name SELECT E.D.

loc 10. Find the name of the manager with their Department names 9. ..DEPTNO.ENAME.DEPT D WHERE E. 2. Find all the names of the employee and manager name 6. Find the name of the Department having highest total comm. Show the names of the employees with their department name SELECT E.do not consider the employee not getting commission 5.D.ASSIGNMENT-3 1.Create a table namely emp_urname as emp CREATE TABLE EMP_SAIKIRAN AS SELECT * FROM EMP. 3.DEPTNO=D. Find the name of the Department having highest total salary 7. Find the dept wise total salary in descending order . Find all the emp with d. .DNAME FROM EMP E. 8. Show all the managers with their jobs 4. Find the name of the employee who gets highest sal+ comm. Find the dept wise total salary in ascending order 11.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.