SQL Answers
SQL Answers
40. Ans:select ename,sal,sal*12 "Annual Salary" from emp order by "Annual Salary"
desc;
41. select ename,sal SA,sal*0.15 HRA,sal*0.10 DA,sal*5/100 PF, sal+(sal*0.15)+
(sal*0.10)-(sal*.05) TOTALSALARY from emp ORDER BY TOTALSALARY DESC;
42. select deptno,count(*) from tvsemp group by deptno;
43. select job,count(*) from tvsemp group by job;
44. select deptno,sum(sal) from tvsemp group by deptno;
45. select deptno,max(Sal) from tvsemp group by deptno;
46. select job,sum(sal) from tvsemp group by job;
47. select job ,min(sal) from tvsemp group by job;
48. select deptno ,count(*) from tvsemp group by deptno having count(*)>3;
49. select job,sum(sal) from tvsemp group by job having sum(SAl)>40000;
50. select job,count(*) from tvsemp group by job having count(*)>3;
51. select ename, sal from tvsemp where sal>=(select max(sal) from tvsemp );
52. select ename,empno from tvsemp where sal=(select max(sal) from tvsemp where
job='CLERK') and job='CLERK' ;
53. select ename,sal from tvsemp where sal>(select max(sal) from tvsemp where
job='CLERK') AND job='SALESMAN';
54. select ename,sal from tvsemp where sal>(select min(sal) from tvsemp where
job='SALESMAN') and job='CLERK';
55. select ename,sal from tvsemp where sal>all(select sal from tvsemp where
ename='JONES' OR ename='SCOTT');
56. select ename,sal,deptno from tvsemp where sal in (select max(sal) from tvsemp
group by deptno);
57. select ename,job from tvsemp where sal in (select max(sal) from tvsemp group by
job);
58. select e.ename,d.dname from emp e,dept d where e.deptno=d.deptno and
d.dname='ACCOUNTING';
59. select e.ename,d.loc from emp e,tvsdept d where e.deptno=d.deptno and
d.loc='CHICAGO';
60. select job ,sum(sal) from tvsemp group by job having sum(sal) >(select max(sal)
from tvsemp where job='MANAGER');
61. select ename,deptno from tvsemp where sal>any(select min(sal) from tvsemp
where deptno!=10 group by deptno) and deptno=10 ;
62. select ename,deptno from tvsemp where sal>all(select max(sal) from tvsemp
where deptno!=10 group by deptno) and deptno=10 ;
63. select upper(ename) from tvsemp;
64. select Lower(ename) from tvsemp;
65. select InitCap(ename)from tvsemp;
66. select lentgh('RAMA') from dual;
67. select length(ename) from tvsemp;
68. select ename||' '||empno from tvsemp;
69. select substr('Oracle',3,2) from dual;
70. select lstr('Computer Maintenance Corporation','a' ) from dual;
71. select translate('Alliens','A','B') from Dual;
72. select ename ,replace(job,'MANAGER','BOSS') from tvsemp;
73. select empno,ename,deptno,Decode(deptno,10,'ACCOUNTING' ,
20,'RESEARCH',30,'SALES','OPERATIONS')DName from tvsemp;
74. select sysdate-to_date('30-jul-1977') from dual;
89. select e.ename, d.loc from tvsemp e ,tvsdept d where d.loc like('%K') and
ename like('S%')
90. select e.ename Superior, e1.ename Subordinate from tvsemp e,e1 where
e.empno=e1.mgr and e.ename='JONES';
91. select ename, sal, (sal+(sal*0.20)) from tvsemp where (sal+(sal*0.20))>3000;
92. select e.ename, d.dname from tvsemp e, tvsdept d where e.deptno=d.deptno
93. select e.ename, d.dname from emp e, dept d where e.deptno=d.deptno and
d.dname='SALES';
94. Select e.ename, d.dname, e.sal, e.comm from tvsemp e, dept d where
e.deptno=d.deptno and sal between 2000 and 5000;
95. Select e.ename, e.sal, e1.ename,e1.sal from tvsemp e,e1 where
e.mgr=e1.empno and e.sal>e1.sal;
96. select e.ename,e.deptno,e1.ename,e1.deptno from tvsemp e,e1 where
e.mgr=e1.empno and e.deptno=e1.deptno;
97. select ename from tvsemp where mgr is null;
98. select ename,grade,deptno,sal from tvsemp ,salgrade where ( grade,sal) in
(select grade, sal from salgrade, tvsemp where sal between losal and hisal)
and grade!=4 and deptno in (10,30) and hiredate<'31-Dec-82';
150. ;
151.
152. select ename,hiredate, LAST_DAY ( next_day(hiredate,'Friday')),
case when to_char(hiredate,'dd') <=('15') then
LAST_DAY ( next_day(hiredate,'Friday'))
when to_char(hiredate,'dd')>('15') then
LAST_DAY( next_day(add_months(hiredate,1),'Friday'))
end case from tvsemp ;
177. select * from emp where sal>(select max(sal) from emp where deptno=30);
178. select * from emp where sal>all(select sal from emp where deptno=30);
179. select deptno from emp group by deptno having count(*)>3;
180. select * from emp where rownum < 11 minus select * from emp where
rownum< 10;
181. select ename, upper(substr(ename,0,length(ename)/2)) ||
lower(substr(ename,length(ename)/2+1, length(ename))) UP_lo from emp
182. create table emp1 as select * from emp;
183. delete from emp where empno = ( select empno from emp where rownum < 11
minus select empno from emp where rownum< 10);
184. create table copyEMP as select * from emp;
185. select distinct(ename) from emp e where ename in (select ename from emp
where e.empno<>empno);
186. select ename from emp order by ename desc;
187. select empno,ename from emp e,salgrade s where e.sal between s.losal and
s.hisal and to_char(hiredate, 'mm')=grade;
188. select * from emp where to_char(hiredate,'dd') =deptno;
189. select substr(ename,1,1)||''||ename from emp;
190. select ename,sal,sal*15/100 pf from emp;
191. .
192. create table emp (empno number(5));
193. alter table emp add ename varchar2(20) not null;
194. alter table emp add constraint emp_empno primary key (empno);
195. alter table emp modify ename varchar2(30);
196. alter table emp add sal number(7,2);
197. alter table emp add constraint emp_sal_check check(sal<10000);
198. alter table emp disable constraint emp_sal_check;
199. alter table emp enable constraint emp_sal_check;
200. alter table emp add mgr number(5);
201. Alter table emp add constraint emp_mgr foreign key (empno;
202. alter table emp add deptno number(3);
203. alter table emp1 add constraint emp1_deptno foreign key (deptno) references
dept(deptno);
204. create table newemp as select * from emp;
205. create table newemp as select empno,ename,dname from emp e,dept d where
e.deptno=d.deptno;
206. delete from emp where floor(sysdate-hiredate)>2*365;
207. select emp set comm=300 where comm is null;
208. update emp set comm=comm*10/100 where comm is not null;
209. select ename,dname from emp e,dept d where e.deptno=d.deptno;
210. select empno,ename,loc from emp e,dept d where e.detpno=d.deptno;
211. select ename,dname from emp e,dept d where e.deptno(+)=d.deptno;
212. select e.ename,m.ename from emp e,emp m where e.mgr=m.empno;
213. select deptno,sum(sal) from emp group by deptno;
214. select deptno,count(*) from emp group by deptno;
215. select table_name from user_constraints where R_constraint_name IN (select
constraint_name FROM USER_CONSTRAINTS WHERE TABLE_NAME =
'&PARENTTABLENAME’) .