Você está na página 1de 3

QUERIES

1. List all columns of Emp.


2. List all jobs of Emp.
3. List all distinct job in Emp.
4. List all information about employees in department 30.
5. Find all department number with department names greater than 20.
6. Find all information about all the managers as wel! as the clerks in department 30
7. List the names ,numbers and deparment of all clerks.
8. Find all the mangers not in, department 30.
9. List information about all employees in department 10 who are not managers or clerks.
10.Find employees and jobs earning between 1200 and 1300.
11.Find employees whose salaries are not between 1200 and 1400.
12.List names and department of employees who are clerks analyst or salesman.
13.List names and departments of employee whose names begin with M.
14.List job and department of employee whose names are five letters long begin with
"ALL..." and end With "N"
15.List employee and jobs in department 30 in order of their salary.
16 List all employees and their jobs in department. 40 in descending order by salary
17.Find salaries and jobs of employees who earn more than Janes.
18.List employees whose salary exceeds their managers.
19.List employees whose commission is greater than 25% of their salaries.
20.Find average salnry of clerks.
21.Find the highest and lowest salaries and the difterence between of them.
22.Find Alien's location,
23.List information about all the employees in Chigaco
24. Use table label to abbreviate the table name
25. Find the salary grade of each employee.
26 Join emp and dept and list department 30 and 40 with or without employees
27.List departments Without employee
28.Make a query that displays salary! in dollar format.
29.Calculate the total compensation for all sales people
30.List sales people in descending order of their commission divided by their salary
31 Calculate total annual compensation for all sales people.
32.Calculate the daily salary of employees in department 30.
33.Find the average salary of clerks.
34.Find the highest and lowest salaries of the employees
35.Count the employees who are eligible to receive a commission.
36.Count the no of Jobs held by employees in department 30
31.List the employee and job with the highest salary
38.List the average salary in each department.
39.Find the average annual sa!ary of the non managerial staff in each department.
40.Count lhe employee and calculate the average annual salary for each job group in each
department
41.List the average annual salary for the Job groups with more than two employees.
42.List all department with atleast two clerk.
43.List all the job groups whose average salary exceeds that of managers.
44.Replace the __expression avg(sal) with alias.
45.List department 20 employees jobs and hire dates formatted like "WEDNESDAY
JANUARY 12,1983"
46.Display employee hire dates in format like "WED 12th of JANUARY 1983"
47.Compute the no.of days remaining in this year.
48.Display infonmation about all employees who are not eligible to receive commission
49.Find the total salary and total commission of sales people.
50.Find the second maximum salary in emp table.

ANSWERS

1. SELECT * FROM EMP;


2. SELECT JOB FROM EMP;
3. SELECT DISTINCT(JOB) FROM EMP;
4. SELECT * FROM EMP WHERE DEPTNO=30;
5. SELECT DEPTNO,DNAME FROM DEPT WHERE DEPTNO > 20;
6. SELECT * FROM EMP WHERE DEPTNO=30 AND JOB IN (`MANAGER',
`CLERK');
7. SELECT ENAME,EMPNO,DEPT FROM EMP WHERE JOB = `CLERK';
8. SELECT * FROM EMP WHERE JOB='MANAGER' AND DEPTNO !=30;
9. SELECT * FROM EMP WHERE DEPTNO=10 AND JOB NOT IN
(`MANAGER','CLERK');
10. SELECT ENAM JOB FROM EMP WHERE SAL BETWEEN 1200 AND 1300;
11. SELECT ENAME FROM EMP WHERE SAL NOT BETWEEN 1200 AND 1400;
12. SELECT ENAME , JOB, DEPTNO FROM EMP WHERE JOB IN (`CLERK',
`ANALYST', `SALESMAN');
13. SELECT ENAME , JOB,DEPTNO FROM EMP WHERE ENAME LIKE `M %' ;
14. SELECT ENAME , JOB FROM EMP WHERE ENAME LIKE `ALL_N';
15. SELECT ENAME , JOB FROM EMP WHERE DEPTNO=30 ORDER BY SAL;
16. SELECT ENAME, JOB FROM EMP WHERE DEPTNO=40 ORDER BY SAL
DESC;
17. SELECT SAL,JOB FROM EMP WHERE SAL>(SELECT SAL FROM EMP
WHERE ENAME='JONES');
18. SELECT X.SAL,X.ENAME FROM EMP X, EMP Y WHERE X.SAL > Y.SAL
AND Y.JOB = `MANEGER';
19. SELECT ENAME FROM EMP WHERE COMM>SAL*25 / 100;
20. SELECT AVG(SAL) FROM EMP WHERE JOB='CLERK';
21. SELECT MAX(SAL) ,MIN(SAL),MAX(SAL)-MIN(SAL) FROM EMP;
22. SELECT ENAME, LOC FROM EMP , DEPT WHERE EMP.DEPTNO =
DEPT.DEPTNO AND ENAME='ALLEN';
23. SEELCT EMP.* FROM EMP, DEPT WHERE EMP.DEPTNO = DEPT.DEPTNO
AND LOC = `CHICAGO';
24. SELECT E.*, D.* FROM EMP E , DEPT D WHERE D.DEPTNO = E.DEPTNO ;
25. SELECT ENAME,SALGRADE FROM EMP, SALGRADE WHERE SAL
BETWEEN LOSAL AND HISAL;
26. SELECT EMP.* , DEPT.* FROM EMP , DEPT WHERE DEPT.DEPTNO =
EMP.DEPTNO(+);
27. SELECT DEPTNO FROM DEPT WHERE DETPNO NOT IN (SELECT DISTINCT
(DEPTNO) FROM EMP);
28. SQL > COL SAL FORMAT $9999.99; (Hit Enter Key And Then Type : SELECT
SAL FROM EMP;
29. SELECT EMU(SAL) FROM EMP WHERE JOB = `SALESMAN';
30. SELECT * FROM EMP WHERE JOB = `SALESMAN' ORDER BY COMM/SAL
DESC;
31. SELECT SUM(SAL*12) FROM EMP WHERE JOB = `SALESMAN';
32. SELECT SAL/30.5 FROM EMP WHERE DEPTNO=30;
33. SEELCT AVG(SAL) FROM EMP WHERE JOB='CLERK';
34. SELECT MAX(SAL), MIN(SAL) FROM EMP;
35. SELECT COUNT(ENAME) FROM EMP WHERE COMM IS NOT NULL;
36. SELECT COUNT(JOB) FROM EMP WHERE DEPTNO=30;
37. SELECT ENAME , JOB FROM EMP WHERE SAL=(SEELCT MAX(SAL) FROM
EMP);
38. SELECT DEPTNO, AVG(SAL) FROM EMP GROUP BY DEPTNO;
39. SELECT DEPTNO,AVG(SAL*12) FROM EMP WHERE EMPNO NOT IN
(SELECT DISTINCT(MGR) FROM EMP) GROUPS BY DEPTNO;
40. SELECT COUNT(ENAME), AVG(SAL*12), JOB , DEPTNO FROM EMP GROUP
BY JOB, DEPTNO;
41. SELECT JOB , AVG(SAL*12) FROM EMP GROUP BY HOB HAVING
COUNT(*) >2;
42. SELECT DEPTNO FROM EMP WHERE JOB = `CLERK' GROUP BY DEPTNO
HAVING COUNT(*)>=2;
43. SELECT JOB FROM EMP WHERE SAL > ALL(SELECT SAL FROM EMP
WHERE JOB = `MANAGER') GROUP BY JOB;
44. SELECT AVG(SAL) "AVERAGE SALARY" FROM EMP;
45. SELECT ENAME , JOB , TO_CHAR(HIREDATE,'DAY MONTH D YYYY')
FROM EMP WHERE DEPTNO=20;
46. SELECT TO_CHAR(HIREDATE,'Dy d "th of" MONTH YYYY') FROM EMP;
47. SEELCT 365-TO_CAHR(TO_DATE(SYSDATE),'DDD') FROM DUAL;
48. SELECT * FROM EMP WHERE COMM IS NUL;
49. SELECT SUM(SAL), SUM(NUL(COMM,0)) FROM EMP WHERE
JOB='SALESMAN';
50. SELECT MAX(SAL) FROM EMP WHERE SAL < (SELECT MAX(SAL) FROM
EMP);

Você também pode gostar