You are on page 1of 14

1

1. List all dept names and locations from dept table: Query: select deptname,location from dept; DEPTNAME management sports engineering Medical LOCATION dehradun haldwani haridwar Kotdwar

2. List the employees belonging to dept 2: Query: select * from emp where deptno=2; EMPNO EMPNAME JOB HIREDATE SALARY COMMISION DEPTNO 5 mannu doc 01-AUG-10 1000000 1000 2 8 gagu clerk 02-JUL-11 2000000 20 2

3. List the name & salary of the employee whose salary is more than rs200000: Query: select empname,salary from emp where salary>200000; EMPNAME shubham mannu gagan gaurav gagu SALARY 1000000 1000000 2000000 1000000 2000000

4. List the names of clerk where deptno=2: Query: select empname from emp where deptno=2 and job='clerk'; EMPNAME gagu

5. List the names of architect and doctor. Query: select empname from emp where job='doc' or job='architect'; EMPNAME mannu gaurav

6. List the details of the employees who have joined before the end of Sept 09. Query: select * from emp where job='doc' and hiredate>'1-sep-2009'; EMPNO EMPNAME JOB HIREDATE SALARY COMMISION DEPTNO 5 mannu doc 01-AUG-10 1000000 1000 2

7. List the names of employee who are not doc. Query: select empname from emp where not job='doc'; EMPNAME rahul sachin rahul shubham gagan

gaurav gagu

8. List all dept no ,employee no from emp table. Query : select empno,deptno from emp; EMPNO 2 1 2 3 5 6 7 8 DEPTNO 1 1 1 3 2 3 1 2

9. List all employee names along with their salary from emp table: Query : select empname,salary from emp; EMPNAME rahul sachin rahul shubham mannu gagan gaurav gagu SALARY 10000 100000 10000 1000000 1000000 2000000 1000000 2000000

10. List information about all dept from emp table. Query: select * from emp; EMPN O 2 1 2 3 5 EMPNAM E rahul sachin rahul shubham mannu HIREDAT SALAR COMMISIO DEPTN E Y N O engineer 12-SEP-10 10000 5000 1 engineer 01-MAR-09 100000 5000 engineer 01-SEP-10 10000 2000 1 clerk 02-JUL-10 1000000 1000 doc 01-AUG-10 1000000 1000 2 professo 02-AUG-07 2000000 3 r architect 02-JUL-10 1000000 100 1 clerk 02-JUL-11 2000000 20 2 JOB

6 gagan 7 gaurav 8 gagu

11. LIST the names of employees whose Numbers are 2,3,5. Query: select empname from emp where empno in (2,3,5); EMPNAME rahul rahul shubham mannu

12. LIST the employee details not belonging to the dept. 1,2. Query: select empname from emp where deptno in (1,2); EMPNAME rahul sachin rahul

mannu gaurav gagu

13. LIST empname ,salary whose salary is between 10000 and 100000: Query : select empname,salary from emp where salary BETWEEN 10000 AND 100000; EMPNAME rahul sachin rahul SALARY 10000 100000 10000

14. LIST emp details who joined before 1-march-09 and 2-jul-10: Query : select * from emp where hiredate not between '01-mar-09' and '02-jul-10'; EMPN O 2 2 5 EMPNAM HIREDAT SALAR COMMISIO DEPTN JOB E E Y N O rahul engineer 12-SEP-10 10000 5000 1 rahul engineer 01-SEP-10 10000 2000 1 mannu doc 01-AUG-10 1000000 1000 2 professo 6 gagan 02-AUG-07 2000000 3 r 8 gagu clerk 02-JUL-11 2000000 20 2

15. LIST employee name who are not eligible for commission: Query : select empname from emp where commision is null ; EMPNAME gagan

16. LIST the emp name not assigned to any department: Query: select * from emp where deptno is not null; EMPNAME rahul rahul mannu gagan gaurav gagu

17. LIST employee name who are eligible for commission. Query: select empname from emp where commision is not null ; EMPNAME rahul sachin rahul shubham mannu gaurav gagu

18. LIST the details of employee whose salary is greater than 10000 and commission is null. Query: select * from emp where salary>10000 and commision is null;

EMPN EMPNAM O E 6 gagan

JOB

HIREDAT SALAR COMMISIO DEPTN E Y N O 2000000 3

professo 02-AUG-07 r

19. ALTER TABLE: Query: ADDalter table emp add nex varchar2(20); select * from emp; EMPN EMPNAM O E 2 rahul 1 sachin 2 rahul 3 shubham 5 mannu 6 gagan 7 gaurav 8 gagu JOB enginee r enginee r enginee r clerk HIREDAT SALAR COMMISIO DEPTN NE E Y N O X 12-SEP-10 01-MAR09 01-SEP-10 10000 100000 10000 5000 5000 2000 1000 1000 2 3 100 20 1 2 1 1

02-JUL-10 1000000 01-AUGdoc 1000000 10 profess 02-AUG2000000 or 07 architec 02-JUL-10 1000000 t clerk 02-JUL-11 2000000

DROP COLUMNalter table emp drop column nex;

select * from emp; EMPN O 2 1 2 3 5 EMPNAM E rahul sachin rahul shubham mannu HIREDAT SALAR COMMISIO DEPTN E Y N O engineer 12-SEP-10 10000 5000 1 engineer 01-MAR-09 100000 5000 engineer 01-SEP-10 10000 2000 1 clerk 02-JUL-10 1000000 1000 doc 01-AUG-10 1000000 1000 2 professo 02-AUG-07 2000000 3 r architect 02-JUL-10 1000000 100 1 clerk 02-JUL-11 2000000 20 2 JOB

6 gagan 7 gaurav 8 gagu

MODIFYALTER TABLE emp modify(job char(20)); desc emp; Name EMPNO EMPNAME JOB HIREDATE SALARY COMMISION DEPTNO Null? Type NUMBER(4) VARCHAR2(40) CHAR(20) DATE NUMBER(9,2) NUMBER(7,2) NUMBER(2)

20. List the employee whose name start with s. Query: select * from emp where empname like s%;

EMPN EMPNAM O E 1 sachin 3 shubham

JOB

HIREDAT SALAR COMMISIO DEPTN E Y N O 100000 1000000 5000 1000

enginee 01-MAR-09 r clerk 02-JUL-10

21. List the employee whose name end with m. Query: select * from emp where empname like '%m'; EMPNO EMPNAME JOB HIREDATE SALARY COMMISION DEPTNO 3 shubham clerk 02-JUL-10 1000000 1000

22. List the employee whosename has exactly 5 characters. Query: select * from emp where empname like '_____'; EMPN O 2 2 5 EMPNAM HIREDAT SALAR COMMISIO DEPTN JOB E E Y N O rahul engineer 12-SEP-10 10000 5000 1 rahul engineer 01-SEP-10 10000 2000 1 mannu doc 01-AUG-10 1000000 1000 2 professo 6 gagan 02-AUG-07 2000000 3 r

23. List the employee name having a as the second character. Query: select * from emp where empname like '_a%'; EMPN O 2 1 2 EMPNAM HIREDAT SALAR COMMISIO DEPTN JOB E E Y N O rahul engineer 12-SEP-10 10000 5000 1 sachin engineer 01-MAR-09 100000 5000 rahul engineer 01-SEP-10 10000 2000 1

10

5 mannu 6 gagan 7 gaurav 8 gagu

doc professo r architect clerk

01-AUG-10 02-AUG-07 02-JUL-10 02-JUL-11

1000000 2000000 1000000 2000000

1000

2 3

100 20

1 2

24.List the empno,empname,salary in ascending orderof salary. Query: select empno,empname,salary from emp order by salary; EMPNO 2 2 1 3 7 5 6 8 EMPNAME rahul rahul sachin shubham gaurav mannu gagan gagu SALARY 10000 10000 100000 1000000 1000000 1000000 2000000 2000000

25. List empno,empname , deptno.&salary In decending order of department no & salary. Query: select empno,empname,deptno,salary from emp order by deptno,salary desc; EMPNO 7 2 2 8 5 6 EMPNAME gaurav rahul rahul gagu mannu gagan DEPTNO 1 1 1 2 2 3 SALARY 1000000 10000 10000 2000000 1000000 2000000

11

3 shubham 1 sachin

1000000 100000

26. List the name,salary&providentfund of all employees(Provident fund is 10% of salary) Query: select empname,salary,salary*0.1 as "provident fund" from emp; EMPNAME rahul sachin rahul shubham mannu gagan gaurav gagu SALARY 10000 100000 10000 1000000 1000000 2000000 1000000 2000000 provident fund 1000 10000 1000 100000 100000 200000 100000 200000

27. List the empname,salary, provident fund,hra,da & gross salary. Query: select empname,salary,salary*0.1 as "provident fund",salary*0.5 as "hra",salary*0.3 as "da",salary+salary*0.5+salary*0.3-salary*0.1 as "gross salary" from emp; EMPNAME SALARY provident fund hra da gross salary rahul 10000 1000 5000 3000 17000 sachin 100000 10000 50000 30000 170000 rahul 10000 1000 5000 3000 17000 shubham 1000000 100000 500000 300000 1700000 mannu 1000000 100000 500000 300000 1700000 gagan 2000000 200000 1000000 600000 3400000 gaurav 1000000 100000 500000 300000 1700000 gagu 2000000 200000 1000000 600000 3400000

12

28. List the no of employees with the company. Query: select count(empname) from emp; COUNT(EMPNAME) 8

29. List no of jobs available in the emp table. Query: select count(job) from emp; COUNT(JOB) 8

Query: select count(distinct(job)) from emp; COUNT(DISTINCT(JOB)) 5

30.List total salary payable to employee. Query: select SUM(salary) from emp; SUM(SALARY) 7120000

31.List max salary from emp working as the engineer. Query: select MAX(salary) from emp where job='engineer'; MAX(SALARY) 100000

13

32. List min salary from emp table. Query: select MIN(salary) from emp; MIN(SALARY) 10000

33. List the avg salary& the no of emp working in dept no 10. Query: select avg(salary),count(empname) from emp where deptno=1; AVG(SALARY) 340000 COUNT(EMPNAME) 3

34. List deptno and no of emp in each dept. Query: select deptno,count(*) from emp group by deptno; DEPTNO 1 2 3 4 COUNT(*) 3 2 1 2

35. List deptno & the total salary payable in each department. Query: select deptno,sum(salary) from emp group by deptno; DEPTNO 1 2 3 SUM(SALARY) 1020000 3000000 2000000 1100000

14

36. List the jobs & the no of employees in each job. Query: select job,count(empno) from emp group by job; JOB architect clerk doc engineer professor COUNT(EMPNO) 1 2 1 3 1

37. List the total, max, min & avg salary of employee job wise. Query: select job,sum(salary),max(salary),min(salary),avg(salary) from emp group by job; JOB SUM(SALARY) MAX(SALARY) MIN(SALARY) AVG(SALARY) architect 1000000 1000000 1000000 1000000 clerk 3000000 2000000 1000000 1500000 doc 1000000 1000000 1000000 1000000 engineer 120000 100000 10000 40000 professor 2000000 2000000 2000000 2000000

38. List the avg salary of all dept employee more than 2 peoples. Query: select job,avg(salary) from emp group by job having count(*)>2; JOB engineer AVG(SALARY) 40000

You might also like