在学习过程中,想要练习select语句,看到JoneClassMate的Oracle查询操作练习题,模拟练习:
1.取前几条数据
select e.*,rownum from emp e where rownum<=5;
2.先根据部门编号升序,再根据薪水降序。
select * from emp order by deptno asc,sal desc;
3.查询出雇员表(emp)中comm为null的记录。
select * from emp where comm is null;
4.查询出雇员表(emp)中员工的姓名,将名字中的’A’换为’1’
select replace(ename,'A','1') from emp;
5.查询出每个部门的平均薪水,并显示出部门详细信。
select deptno,avg(sal) from emp e group by deptno;
6.查询出部门人员中薪水大于2000的人在2个以上的部门。
select count(deptno),deptno from emp where sal > 2000
group by deptno having (count(deptno)>=2) ;
7.求出每个部门中薪水最高的员工。
select empno,ename,sal,deptno from emp e1 where sal =
(select max(sal) from emp e2 where e1.deptno=e2.deptno)
order by deptno;
8.分别统计出各个月份入职(hiredate)的员工有多少人
select count(*),extract(month from hiredate) from
emp group by extract(month from hiredate) order by extract(month from hiredate);
9.查询scott.emp表中所有列。
select * from emp;
10.查询scott.emp表中的ename列。
select ename from emp;
11.查询scott.emp表中ename列,将其列名改为“雇员姓名”。
select ename "雇员姓名" from emp;
12.查询scott.emp表中sal、comm两项工资的总和。
select ename,sal+nvl(comm,0) from emp;
13.消除emp表中job列的重复值。
select distinct(job) from emp;
14.查看scott.emp表中在10号部门的所有员工具体情况。
select * from emp where deptno = 10;
15.查询scott.emp表中工资在1500和3000之间的雇员编号。
select empno from emp where sal between 1500 and 3000;
125



被折叠的 条评论
为什么被折叠?



