SQL语句练习题一
1、选择部门30中的所有员工;
SQL> select * from emp where deptno = 30;
2、列出所有办事员(CLERK)的姓名,编号和部门编号;
SQL> select empno,ename,deptno from emp where job='CLERK';
3、找出奖金高于工资的员工;
SQL> select * from emp where comm>sal;
4、找出奖金高于工资的60%的员工;
SQL> select * from emp where comm>(sal*0.6);
5、找出部门10中的所有经理(MANAGER)和部门20中所有的办事员(CLERK)的详细资料;
SQL>select * from emp
where (deptno=10 and job='MANAGER') or (deptno=20 and job='CLERK');
6、找出部门10中所有的经理(MANAGER),部门20中所有办事员(CLERK),既不是经理又不是办事员但其工资大于或等于2000的所有员工的详细资料;
select * from emp
where (deptno=10 and job='MANAGER')
or (deptno=20 and job='CLERK')
or ((Job!='MANAGER' and job!='CLERK') and sal > =2000);
7、找出收取奖金的员工的不同工作;
SQL> select job from emp where comm is not null;
SQL> select job from emp where not comm is null;
SQL> select distinct job from emp where not comm is null;
8、找出不收取奖金或者收取的奖金低于100的员工;
SQL> select * from emp where comm is null or comm <100;
9、找出各月倒数第三天受雇的所有员工;
select to_char(hiredate,' dd')day1 from emp;
select to_char(last_day(hiredate),' dd')day2 from emp;
select * from emp where