sql assignment
sql assignment
select *
from employees;
select *
from departments;
5. display the employee no and total salary for all the employees.
6. display the employee name and annual salary for all the employees.
7. display the names of all employees who are working in depart number 10.
8. display the names of all employees who are working as clerks and drawing a
salary more than 3000.
9. display the employee number and name who are earning comm.
10. display the employee number and name who do not earn any comm.
11) display the names of empoyees who are working as clerks, salesman or analyst
and drawing a salary more than 3000.
select first_name||' '||last_name as name
from employees
where job_id IN ('CLERK','SALESMAN','ANALYST') and salary>3000;
12. display the names of the employees who are working in the company for the past
5 years.
13) display the list of employees who have joined the company before 30_jun_90 or
after 31_dec_90.
19. display the names of employees whose name starts with alphabet s.
20. display the employee names for employees whose name ends with alphabet S.
select first_name||' '||last_name name
from employees
where first_name||' '||last_name Like '%s';
O/P
21. display the names of employees whose names have second alphabet A in their
names.
select first_name||' '||last_name name
from employees
where first_name||' '||last_name Like '_a%';
22. select the names of the employee whose names is exactly five characters in
length.
select first_name||' '||last_name name
from employees
where first_name||' '||last_name Like '_____';
(or)
select first_name||' '||last_name name
from employees
where length(first_name||' '||last_name)=5;
(or)
select last_name name
from employees
where length(last_name)=5;
23. display the names of the employees who are not working as MANAGERS.
select first_name||' '||last_name name
from employees
where job_id!='MANAGER';
24. display the names of the employee who are not working as salesman or clerk or
analyst.
select first_name||' '||last_name name
from employees
where job_id NOT IN ('CLERK','SALESMAN','ANALYST');
25. display all rows from emp table.the system should wait after every screen full
of information
set pause on
select *
from emp;
26. display the total number of employees working in the company.
select count(employee_id) no_employees
from employees;
(or)
select sum(salary)
from employees;
32. Display the maximum salary being paid to depart number 20.
select max(salary) max_salary
from employees
where department_id=20;
36. DISPLAY the names of the employees in order of salary i.e..the name of the
employee earning lowest salary should appear first.
select first_name||' '||last_name names
from employees
order by salary asc;
37. display the names of the employee in descending order of salary.
select first_name||' '||last_name names,salary
from employees
order by salary desc;
39. display empno, ename,deptno, sal sort the output first be on name and within
name by deptno and within deptno by sal.
select empno,ename,deptno,sal
from emp
order by ename,deptno,sal;
40. display the name of the employee along with their annual salary(sal*12).the
name of the employee earning highest annual salary should apper first.
select first_name||' '||last_name names, salary*12 annual_salary
from employees
order by annual_salary desc;
41. display name,salary,hra,pf,da,total salary for each employee. the output should
be in the order of total salary, hra 15% of salary, da 10% of salary, pf salary,
total salary will be(salary_hra_da)-pf.
select ename,sal,(sal+hra+da)-pf total_salary,sal*0.15 hra,sal*0.1 da,sal*0.5
pf
from emp;
42. display department numbers and total number of employees working in each
department.
select department_id, count(employee_id) number_of_emp
from employees
group by department_id;
43. display the various jobs and total number of employees with each job group.
select job_id,count(employee_id) number_of_emp
from employees
group by job_id;
44.display the depart numbers and total salary for each department.
select department_id,sum(salary) total_salary
from employees
group by department_id;
45. display the depart numbers and max salary for each department.
select department_id,max(salary)
from employees
group by department_id;
46. display the various jobs and total salary for each job.
48. display the depart numbers with more than three employees in each dept.
select department_id,count(employee_id) number_of_emp
from employees
group by department_id
having count(employee_id)>3;
49. display the various job along with total salary for each of this jobs where
total salary is greater than 40000.
50. display the various jobs along with total number of employees in each job. the
output should contain only those jobs with more than three employees.
select job_id,count(employee_id)s
from employees
group by job_id
having count(employee_id)>3;
51) search for the employees with the pattern 'A_B' in their names.
select first_name||' '||last_name names
from employees
where first_name like 'A_b%';
52. find the first occurence of character 'a' from the following string i.e
'computer Maintaince Corporation'.
select INSTR ('Computer Maintaince Corporation','a') from dual;
53. display the information from emp table. where job manager is found it should be
displayed boss(use replace function).
59. select the name of the employee concatenate with employee number.
select first_name||' '||last_name||employee_id names_empid
from employees;
60. use aapropriate function and extract 3 characters starting from 2 characters
from the following string 'oracle.i.e. the output should be 'rac'.
61. display empno, ename, deptno from emp table. instead of display department
numbers display the related department name(use decode function).
select
e.empno,e.ename,decode(e.deptno,10,'ACCOUNTING',20,'RESEARCH',30,'SALES',40,'OPERAT
IONS') DNAMES
from emp e;
62. Display the current date as 15th august friday nineteen ninety seven.
Select to_char(sysdate,'YYYYSP') from dual;
63. display the following output for each row from emp table.
for ex:
scott has joined the company on wednesday 13th august nineteen ninety.
sham hass joined the company on wednesday 13th august nineteen ninety.
64. find the date for nearest saturday after current date.
select next_day(sysdate,'SAT') nearest_sat from dual;
65. display the date three months before the current date.
66. select ename from emp where sal =(select max(sal) from emp);
67. select emp_no,ename from emp where SAL = (SELECT MAX(SAL) FROM EMP WHERE
JOB='CLERK');
68. SELECT ENAME FROM EMP WHERE JOB = 'SALESMAN' AND SAL>(SELECT MAX(SAL) FROM EMP
WHERE JOB='CLERK');
69. SELECT ENAME FROM EMP WHERE JOB='CLERK' AND SAL>ANY(SELECT SAL FROM EMP WHERE
JOB='SALESMAN');
70. SELECT ENAME FROM EMP WHERE SAL >(SELECT SAL FROM EMP WHERE ENAME='JONES') OR
SAL>(SELECT SAL FROM EMP WHERE ENAME='SCOTT');
73. SELECT ENAME FROM EMP WHERE DEPTNO=(SELECT DEPTNO FROM DEPT WHERE LOC
='CHICAGO');
74. SELECT JOB FROM EMP WHERE SAL>(SELECT MAX(SAL) FROM EMP WHERE JOB='MANAGER')
GROUP BY JOB;
75. SELECT ENAME FROM EMP WHERE DEPTNO=10 AND SAL>ANY(SELECT SAL FROM EMP WHERE
DEPTNO IN('20','30'));
76. SELECT ENAME FROM EMP WHERE DEPTNO=10 AND SAL>ALL(SELECT SAL FROM EMP WHERE
DEPTNO IN('20','30'));
77. SELECT JOB FROM EMP WHERE DEPTNO = 10 AND JOB IN(SELECT JOB FROM EMP WHERE
DEPTNO=20);
78. SELECT DISTINCT JOB FROM EMP WHERE DEPTNO = 10 AND JOB IN(SELECT JOB FROM EMP
WHERE DEPTNO=20);
79. SELECT JOB FROM EMP WHERE DEPTNO=10 AND JOB NOT IN(SELECT JOB FROM EMP WHERE
DEPTNO IN('20','30'));
83. select ename from emp where hiredate<'31-dec-82' and deptno =(select deptno
from dept where loc in('NEWYORK','CHICAGO'));
85. SELECT e.ename employee,m.ename manager from emp e,emp m where e.mgr=m.emp_no
and m.ename='JONES';
86. select ename,sal,grade from emp,salgrade where sal in hisal and ename ='FORD'
AND HISAL=SAL;
90. SELECT ENAME FROM EMP WHERE SAL=(SELECT MAX(SAL) FROM EMP);
91. select * from emp where sal= (select (max(sal)+min(sal))/2 from emp);
92. select count(*) from emp group by deptno having count(*) > 3;
95. select count(*) from emp e,emp m where e.mgr=m.empno and e.sal>m.sal;
96. select dname,ename from emp,dept where emp.deptno(+) = dept.deptno and ename is
null;
101. select * from emp where deptno =ANY(select deptno from DEPT where dname
in('SALES','RESEARCH'));
103. delete from emp where deptno in (select deptno from emp group by deptno having
count (*)>3);
104. select dname,ename from emp,dept where emp.deptno(+) = dept.deptno and ename
is null;
107. select * from emp where rownum<11 minus select * from emp where rownum<10;
108. DELETE FROM EMP WHERE EMPNO=(SELECT EMPNO FROM EMP WHERE ROWNUM<11
MINUS
SELECT EMPNO FROM EMP WHERE ROWNUM<10);
note : we can get the deleted rows by this statemnt "insert into emp
(select * from emp as of timestamp to_timestamp('2022-07-24','yyyy-mm-dd
hh:mi:ss'));"
120. Delete from emp where rowid not in(select min(rowid)from emp group by ename) ;
121. select * from emp where rownum<8 minus select * from emp where rownum<5;
123. select * from (select * from emp order by sal desc) where rownum <4 ;
124. SELECT ename,deptno,sal FROM emp WHERE sal> (SELECT MAX(AVG(sal)) FROM emp
GROUP BY deptno );