标签:
简单查询部分sql练习题
-- 选择部门30中的全部职工 select * from emp where deptno = 30; -- 列出全部业务员(CLERK)的姓名,编号,和部门编号 select e.ename, e.empno, e.deptno from emp e where e.job = 'CLERK'; -- 找出奖金高于薪金的员工 select * from emp where comm > sal; -- 找出奖金高于薪金的60%的员工 select * from emp where comm > sal * 0.6; -- 找出部门10中全部经理(MANAGER)和部门20中全部业务员(CLERK)的具体资料 select * from emp e where e.deptno = 10 and e.job = 'MANAGER' or e.deptno = 20 and e.job = 'CLERK'; select * from emp e where (e.deptno = 10 and e.job = 'MANAGER') or (e.deptno = 20 and e.job = 'CLERK'); select * from emp e where e.deptno = 10 and e.job = 'MANAGER' union select * from emp e where e.deptno = 20 and e.job = 'CLERK'; -- 找出部门10中全部经理(MANAGER),部门20中全部业务员(CLERK),既不是经理又不是业务员但其薪水大于等于2000的全部员工的具体资料 select * from emp e where e.deptno = 10 and e.job = 'MANAGER' union select * from emp e where e.deptno = 20 and e.job = 'CLERK' union select * from emp e where e.sal > 2000 and e.job not in('MANAGER', 'CLERK'); -- 找出收取奖金的员工的不同工作 select distinct e.job from emp e; -- 找出不收取奖金或收取的奖金低于100的员工 select * from emp e where e.comm is null or e.comm < 100; -- 找出各月倒数第3天受雇的全部员工 select * from emp e where e.hiredate between last_day(hiredate)-3 and last_day(hiredate); -- 找出早于30年前受雇的员工 select * from emp e where (sysdate - e.hiredate)/365 > 30; -- 以首字母大写的方式显示全部员工的姓名 select initcap(ename) from emp; -- 显示正好为5个字符的员工姓名 select * from emp where length(ename) = 5; -- 显示不带有”R”的员工姓名 select * from emp where ename not like '%K%'; -- 显示全部员工姓名的前三个字符 select substr(ename, 0, 3) from emp; -- 显示全部员工的姓名,并用’a’替换全部’A’ select replace(ename, 'A', 'a') from emp; -- 显示满30年服务年限的员工姓名和受雇日期 select * from emp where (sysdate - hiredate)/365 > 30; -- 显示员工的具体资料,按姓名由大到小排序 select * from emp order by ename desc; -- 显示员工的姓名和受雇日期。依据其服务年限,将最老的员工排在最前面 select ename, hiredate from emp order by hiredate asc; -- 显示全部员工的姓名,工作和薪金,按工作降序排列,若工作同样则按薪金升序排序 select ename, job, sal from emp order by job desc, sal asc; select ename, job, sal from emp order by 2 desc, 3; -- 显示全部员工的姓名,增加公司的年份和月份,按受雇日期所在的月排序。若月份同样。则将最早年份排在最前面 select ename, to_number(to_char(hiredate, 'yyyy')) Year, to_number(to_char(hiredate, 'mm')) from emp order by 3 desc, 2 asc; -- 显示一个月为30天的情况所员工的日薪金。忽略余数 select round(sal/30) 日薪 from emp; -- 找出在(不论什么年份)2月受聘的全部员工 select * from emp where to_number(to_char(hiredate, 'mm'))= 2; -- 对每一个员工,显示其增加公司的天数 select ename, round(sysdate - hiredate) Days from emp; -- 显示姓名中任何位置包括“A”的全部员工姓名 select * from emp where upper(ename) like '%A%'; -- 以年月日方式显示全部员工的服务年限 select ename, hiredate, trunc(months_between(sysdate, hiredate) /12) year , trunc(mod(months_between(sysdate, hiredate) , 12 ) ) months , trunc(sysdate - add_months(hiredate,months_between(sysdate, hiredate))) day from emp ;
标签:
原文地址:http://www.cnblogs.com/gcczhongduan/p/5058297.html