[code]
SELECT empno,
ename,
sal,
CASE deptno
WHEN 10 THEN
'财务部'
WHEN 20 THEN
'研发部'
WHEN 30 THEN
'销售部'
ELSE
'未知部门'
END 部门
from scott.emp;
SELECT empno,
ename,
sal,
DECODE(deptno, 10, '财务部', 20, '研发部', 30, '销售部', '未知部门') 部门
FROM scott.emp;
SELECT empno,
ename,
sal,
deptno,
DECODE(sal, 1000, '低', 2000, '一般', 30000, '高', '非常高') 工资
FROM scott.emp;
1、找出年龄小于25岁的员工;
.2、所有员工名字前加上Dear ,并且名字首字母大写;
.3、找出姓名为5个字母的员工;
.4、找出姓名中不带R这个字母的员工;
.5、显示所有员工的姓名的第一个字;
.6、显示所有员工,按名字降序排列,若相同,则按工资升序排序;
.7、分组统计各部门下工资>1000的员工的平均工资;
.8、统计各部门下平均工资大于1300的部门;
.9、算出每个职位的员工数和最低工资;
.10、算出部门30中得到最多工资的员工姓名;
.11、算出每个职位的平均工资,如果平均工资大于3000,
显示“工资不错”,如果平均工资1000到3000,显示“工资一般”,
否则显示“工资差”,按平均工资降序排列;
1.
select * from scott.emp where (months_between(sysdate, hiredate) / 12 > 25)
2.
select lpad(initcap(ename), length(ename) + 4, 'Dear') from scott.emp
3.
select * from scott.emp where length(ename) > 5
4.
select * from scott.emp where ename not like '%R%'
select * from scott.emp where instr(ename, 'R') = 0
5.
select substr(ename, 1, 1) from scott.emp
6.
select *
from scott.emp
order by ename,
case
when exists (select ename from scott.emp) then
sal
end;
select * from scott.emp order by ename, sal asc;
7.
select avg(sal)
from scott.emp
where deptno in
(select deptno from scott.emp where sal > 1000 group by deptno)
group by deptno;
8.
select deptno from scott.emp group by deptno having avg(sal) > 1300
9.
select count(ename), min(sal) from scott.emp group by job
10.
select ename
from scott.emp
where deptno = '30'
and sal = (select max(sal) from scott.emp where deptno = '30')
11.
select job,
avg(sal),
CASE
when avg(sal) > 1000 then
'工资一般'
when avg(sal) > 3000 then
'工资不错'
else
'工资很差'
end 工资情况
from scott.emp
group by job
order by avg(sal) desc;
[/code]