oracle related query statement

1. List ENAME , DEPTNO, SAL of all employees with salary between 1000 and
2000 And sort by department name. select deptno,dname from dept order by dname; 3. Displays all different job types. select job from emp; 4. Query all employees whose names have only 4 characters; select ename from emp where ename like'____'; 5. Query all employees with one of the three MGR numbers of 7902, 7566, 7788: select ename, mgr from emp where mgr=7902 or mgr=7566 or mgr=7788; 6. List all employees with department numbers between 10 and 20, sorted alphabetically by first name. select ename,deptno from emp where deptno>=10 and deptno<=20 order by ename; 7. List the employees whose department number is 20 and whose job is clerk.











select ename,job,deptno from emp where deptno=20 and job='CLERK';
8. Display the names of employees whose names contain TH and LL.
select * from emp where ename like '%TH%' or ename like '%LL%';
9. Display the names and remunerations of all employees.
select ename,sal from emp;
10. Display employees hired in 1982.
select *from emp where to_char (hiredate,'YYYY') ='1982';
11. Query the average salary, minimum salary, and maximum salary of each department.
select deptno,round(avg(sal)),min(sal),max(sal) from emp group by deptno;
12. Query the employee with the highest salary in each department.
select * from emp where sal in (select max(sal) from emp group by deptno);
13. Query the number of employees in each department whose average salary is higher than that of all employees.
select a.deptno,count(*) from emp a,(select deptno,avg(sal) avgsal from emp group by deptno) b where a.deptno=b.deptno and a.sal>b.avgsal group by a.deptno ;
14. Use the all keyword to filter employee records whose salary (sal) is not equal to 3000, 950 and 800 at the same time.
select * from emp where sal!=all(3000,950,800);
15. Use the LIKE keyword to display the information of all employees hired in 1981 in the emp table
select * from emp where hiredate like'%81%' ;
16. In the emp table, query the employee name of TURNER at work, but do not remember the exact spelling of TURNER, but remember that its first character is T, the third character is R, and the fifth character is E.
select ename from emp where ename like'%T_R_E%';
17. Query the name, salary, employment time and department name of the employee whose salary is greater than 3000.
select ename,sal,hiredate,dname from emp inner join dept on emp.deptno=dept.deptno where sal>3000;
18. Query the number of employees in each department whose average salary is higher than that of this department. (5 points)
The result shows: "Dept number", "Number of people with higher salary than average"
select deptno,count(*) from
(select a.deptno,a.ename from emp a,(select avg(sal) avgsal, deptno from emp group by deptno) b
where a.deptno=b.deptno
and a.sal>b.avgsal)
group by deptno;
19. Create a view that associates the dept table with the emp table.
CREATE OR REPLACE VIEW emp_view_complex AS
  SELECT D.DNAME,D.LOC,E.EMPNO,E.ENAME
  FROM EMP E,DEPT D
  WHERE E.DEPTNO = D.DEPTNO
20. Query the name and salary of employees in department 20 through the emp_view_complex view Information and department name and department location.
select ename,sal,dname,loc,deptno from emp_view_complex where deptno=20;
drop view emp_view_complex;
drop view emp_view_union;
21. Query the employee's name, number, department, salary (sal), salary grade, and display the first 6 records in the query result (hint: use the pseudo column rownum
select ename,empno,deptno,sal,grade from emp inner join salgrade on rownum <7;
22. Use "associated subquery" to retrieve the information of employees whose salary is less than the average salary of the same position in the emp table.
select * from emp e  
where sal<(select avg(sal) from emp where job=e.job) ;
23. Query the employee with the lowest salary from EMP. The query result includes the employee's name, job title and department name.
select ename,job,dname from emp inner join dept on emp.deptno=dept.deptno where sal=(select min (sal)from emp);
24. Query the employees with the lowest salary in each department from EMP.
select * from emp where sal in(select min(sal) from emp group by deptno);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324614884&siteId=291194637