Beruflich Dokumente
Kultur Dokumente
com
Q:To count the number of nulls and notnulls in Comm. column of emp
table
A:select count(decode(nvl2(comm,1,2),1,1)) nulls,
count(decode(nvl2(comm,1,2),2,1)) not_nulls from emp
4 4 5 5 5 4 4 31
Q:Display the employes whose salary is greater than his own manager
A:select*from emp e where sal>(select sal from emp where empno=e.mgr)
Q:Disply the employes whose sal is greater than the other managers
A: select * from emp e where sal> any(select sal from emp
where empno in(select distinct mgr from emp where mgr<>e.mgr))
Q:To find the employes who are seniour to the employes who are joined
in the year 1981.
A:SELECT HIREDATE FROM EMP WHERE HIREDATE<ALL
(SELECT HIREDATE FROM EMP WHERE HIREDATE LIKE'%81')
For any quries query me at allam.madhu@gmail.com
Q:To fined the employes who have joined on the same hiredate
A: SELECT * FROM EMP WHERE HIREDATE IN
(SELECT HIREDATE FROM EMP GROUP BY HIREDATE
HAVING COUNT(HIREDATE)>1)
Q:To find the uniquness of the given column for the given table.
A: SELECT 1 YES_UNIQUE FROM DUAL
WHERE 1=(SELECT MAX(COUNT(EMPNO)) FROM EMP
GROUP BY EMPNO)
Q:To delete the managers who are working under king with salary
ranging from 2000 to 3000 and joined in first half of
1981
Q:To delete all the employes who have joined most recently under king.
A: DELETE FROM EMP44 E WHERE MGR=(SELECT EMPNO FROM
EMP44 D WHERE ENAME='KING' AND HIREDATE>E.HIREDATE)
Q:To delete all the grade 1 and grade 2 employes and woring in chicago
and joined in the first half of 81.
A: SELECT E.EMPNO,E.ENAME,S.GRADE,D.LOC,E.HIREDATE
FROM SALGRADE S, DEPT D, EMP E WHERE
E.DEPTNO=D.DEPTNO AND E.SAL BETWEEN S.LOSAL AND
S.HISAL AND S.GRADE IN(1,2) AND D.LOC='CHICAGO'
AND E.HIREDATE BETWEEN '01-JAN-81' AND '30-JUN-81'
Q:To delete all the grade 2 and 3 employes of sales dept and working at
chicago and joined after the all the employes whose hiredate is in the
year1980.
A:DELETE FROM EMP44 WHERE EMPNO IN(SELECT E.EMPNO
FROM EMP44 E,DEPT D,SALGRADE S
WHERE E.DEPTNO=D.DEPTNO
AND E.SAL BETWEEN S.LOSAL AND S.HISAL
AND S.GRADE IN(2,3)
AND D.DNAME ='SALES'
AND D.LOC='CHICAGO'
AND
HIREDATE>ALL(SELECT HIREDATE FROM EMP44 WHERE
HIREDATE LIKE'%80'))
A2.delete from emp e where sal =(select min(sal) from emp d where
d.deptno=e.deptno)
Q:To find the employes who are seniour to their own managers using
corelated sub query.
A: DELETE FROM EMP44 WHERE EMPNO IN
(SELECT E.EMPNO FROM EMP44 E WHERE
HIREDATE< (SELECT HIREDATE FROM EMP WHERE
EMPNO=E.MGR))
Q:To find the employes who are seniour to their own manager using self
join.
A: SELECT E.* FROM EMP E,EMP D WHERE E.MGR=D.EMPNO AND
E.HIREDATE<D.HIREDATE
Q: To list the employes whose salary is less than his own manages and
greater than any of the other managers.
A: select * from emp e where sal<(select sal from emp where empno=e.mgr)
And sal> any(select sal from emp
where empno in(select distinct mgr from emp where mgr<>e.mgr))
Q:/To display the employee name and this manager name for each
record selected.
A: SELECT E.EMPNO,E.ENAME,D.ENAME MGR_NAME FROM EMP
E,EMP D WHERE D.EMPNO=E.MGR
Q:To display all the employes who are working under blake and display
the manager name along with the select list.
A: SELECT * FROM(SELECT E.*,D.ENAME MGR_NAME FROM EMP
E,EMP D WHERE E.MGR=D.EMPNO ) WHERE MGR_NAME='BLAKE'
For any quries query me at allam.madhu@gmail.com
Q:To find the employes who are seniour to all the other managers.
A:SELECT * FROM EMP E WHERE HIREDATE < ALL(SELECT
HIREDate from emp where empno
IN(SELECT DISTINCT MGR FROM EMP WHERE MGR <>
(SELECT EMPNO FROM EMP WHERE EMPNO=E.MGR)))
Q:To count the m's and f's from the column and display in the same row
like
A:SELECT COUNT(DECODE(GENDER1,'M',1))
M,COUNT(DECODE(GENDER1,'F',1)) F FROM GENDER
Q:To find the emps who are senior to his own manager and junior to
any one of the other managers
A: select * from emp e where hiredate <(select hiredate from emp where
empno=e.mgr) and HIREDATE > any(SELECT HIREDate from emp where
empno IN(SELECT DISTINCT MGR FROM EMP
WHERE MGR <>(SELECT EMPNO FROM EMP WHERE
EMPNO=E.MGR)))
DEPT TABLE
SALGRADE TABLE