SELECT *FROM EMP;
–1.查询工资大于1200的员工姓名和工资
SELECT ENAME,SAL FROM EMP WHERE SAL>1200 ;
–2. 查询员工号为7934的员工的姓名和部门号
SELECT EMPNO,ENAME,MGR FROM EMP WHERE EMPNO=7934;
–3. 选择工资不在5000到12000的员工的姓名和工资
SELECT ENAME,SAL FROM EMP WHERE SAL BETWEEN 1600 AND 12000 ORDER BY SAL;
SELECT ENAME ,SAL FROM EMP WHERE SAL>=1600 AND sal <=1200 ORDER BY SAL;
– 4. 选择雇用时间在1981-02-01到1981-05-01之间的员工姓名,职位(job)和雇用时间,按从早到晚排序.
SELECT ENAME,job,HIREDATE FROM EMP WHERE HIREDATE BETWEEN TO_DATE(‘1981-02-01’,‘YYYY-MM-DD’) AND TO_DATE(‘1981-05-01’,‘YYYY-MM-DD’);
–5. 选择在20或10号部门工作的员工姓名和部门号
SELECT ENAME ,MGR FROM EMP WHERE DEPTNO=10 OR DEPTNO=20 ORDER BY DEPTNO;
–6. 选择在1987年雇用的员工的姓名和雇用时间
SELECT ENAME,HIREDATE FROM EMP WHERE EXTRACT(year FROM HIREDATE)=1987;
–7. 选择公司中没有管理者的员工姓名及job
SELECT ENAME,job FROM EMP WHERE NOT JOB LIKE ‘MANAGER’;
–8.找出各月倒数第3天受雇的所有员工.
SELECT * FROM EMP WHERE HIREDATE=(LAST_DAY(HIREDATE)-2);
–9.找出早于12年前受雇的员工.
SELECT FROM EMP WHERE MONTHS_BETWEEN(SYSDATE,HIREDATE)/12>12;
–10.以首字母大写的方式显示所有员工的姓名.
SELECT INITCAP(ENAME) FROM EMP;
–11.显示正好为5个字符的员工的姓名.
SELECT ENAME FROM EMP WHERE ENAME LIKE (’_____’);
–12.显示不带有"R"的员工的姓名
SELECT ENAME FROM EMP WHERE NOT ENAME LIKE ‘%R%’;
–13.显示所有员工姓名的前三个字符
SELECT SUBSTR(ENAME,1,3) FROM Emp;
–14.显示所有员工的姓名,用a替换所有"A"
SELECT REPLACE(ENAME,‘A’,‘a’) FROM EMP;
–15.显示满10年服务年限的员工的姓名和受雇日期.:
SELECT ename,HIREDATE FROM emp where MONTHS_BETWEEN(sysdate, HIREDATE)/12>10;
–16.显示员工的详细资料,按姓名排序.
SELECT FROM EMP ORDER BY ENAME;
–17.显示员工的姓名和受雇日期,根据其服务年限,将最老的员工排在最前面.
SELECT ENAME,HIREDATE FROM EMP ORDER BY HIREDATE asc;
–18.显示所有员工的姓名、工作和薪金,按工作的降序排序,若工作相同则按薪金排序.
SELECT ENAME,JOB,SAL FROM EMP ORDER BY JOB desc, sal asc;
–19.显示所有员工的姓名、加入公司的年份和月份,按受雇日期所在月排序,若月份相同则将最早年份的员工排在最前面.
SELECT ENAME,TO_CHAR(HIREDATE,‘yyyy’),TO_CHAR(HIREDATE,‘mm’) FROM EMP ORDER BY TO_CHAR(HIREDATE,‘mm’)desc,TO_CHAR(HIREDATE,‘yyyy’)asc;
–20.找出在(任何年份的)2月受聘的所有员工。
SELECTFROM EMP WHERE TO_CHAR(HIREDATE,‘mm’)=2;
–21.对于每个员工,显示其加入公司的天数.
SELECT ENAME,JOB,TRUNC(sysdate-HIREDATE,0)days FROM emp;
–22.显示姓名字段的任何位置包含"A"的所有员工的姓名.
SELECT ENAME FROM EMP WHERE ENAME LIKE’%A%’;
–23.查询在1981年入职的员工的总数量
SELECT COUNT(HIREDATE)FROM EMP WHERE EXTRACT(YEAR FROM HIREDATE)=1981;
–24.以年月日的方式显示所有员工的服务年限
SELECT TRUNC(MONTHS_BETWEEN(SYSDATE,HIREDATE)/12,0)years,TRUNC(MOD(MONTHS_BETWEEN(sysdate,HIREDATE),12))months,TRUNC(sysdate-ADD_MONTHS(HIREDATE,MONTHS_BETWEEN(SYSDATE,HIREDATE)))day FROM emp;
–25.列出所有办事员(clerk)的姓名,标号和部门编号
SELECT ENAME,EMPNO,DEPTNO FROM EMP WHERE JOB=‘CLERK’;
–26.找出佣金高于薪金的员工
SELECTFROM EMP WHERE COMM>SAL;
–27.找出佣金高于薪金的60%的员工
SELECT FROM EMP WHERE COMM>(SAL0.6);
–28.找出部门10中所有经理(MANAGER)和部门20中所有办事员(CLERK)的详细资料
SELECT *FROM EMP WHERE (DEPTNO=10 AND JOB=‘MANAGER’)OR(DEPTNO=20 AND JOB=‘CLERK’);
–29.找出收取佣金的员工的不同工作
SELECT distinct JOB FROM EMP WHERE COMM is NOT NULL;
–30.找出不收佣金或佣金低于100的员工;
SELECT *from EMP WHERE NvL(COMM,0)<100;
SQL---语句练习(一)
最新推荐文章于 2024-07-18 15:32:08 发布