sql语句复习题

更新时间:2023-12-16 21:36:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

--1.查询emp表中的所有信息

SELECT*FROMscott.emp;

--2.显示emp表的员工姓名和工资

SELECTscott.emp.ename,scott.emp.salFROMscott.emp;

--3查询emp表中部门编号为20的并且sal大于3000的所有员工信息

SELECT*FROMscott.empWHEREempno=20ANDsal>3000;

--4查询emp表中部门编号为20的或者sal大于3000的所有员工信息

SELECT*FROMscott.empWHEREempno=20ANDsal>3000;

--5使用bettwen and 查询工资在2000到4000之间员工信息

SELECT*FROMscott.empWHEREsalBETWEEN2000AND4000;

--6使用in 查询部门编号10 20的所有员工

SELECT*FROMscott.empWHEREdeptnoIN(10,20);

7、使用like查询所有名字中包括 W的员工信息 select * from scott.emp where enamel like '%w%'

8、使用like查询所有员工名字中第二子字母为W的员工信息 select * from scott.emp where enamel like '_w%'

9、查询所有员工信息并按照部门编号和工资进行排序

select* from scott.emp,scott.dept when scott.emp.empno=scott.dept.deptno and order by sal; 10、显示员工工资上浮20%的结果。

selectscott.emp.salscott.emp.sal*(1+20%) from scott.emp;

11、显示EMP表的员工姓名以及工资和奖金的和。

selectempno,ename, sal, comm, (sal + comm) * 12 from emp;

selectempno, ename, sal, comm, nvl(comm, 0), (sal + nvl(comm, 0)) * 12 income from emp 12、显示DEPT表的内容,使用别名将表头转换成中文显示。

select scott.dept.deptno as \号码\13、查询员工姓名和工资,并按工资从小到大排序。

selectscott.emp.ename,scott.emp.sal from scott.emp order by sal;

14、查询员工姓名和雇佣日期,并按雇佣日期排序,后雇佣的先显示。 selectscott.emp.ename,scott.emp.hiredate from scott.emp order by hiredate;

15、查询员工信息,先按部门编号从小到大排序,再按雇佣时间的先后排序。 select* from scott.emp order by empno and order by hiredate 16、按工资和工作月份的乘积排序(倒序)。

SELECT empno, ename, sal*Months_between(sysdate,hiredate) AS total FROM emp ORDER BY total

17、显示职务为“SALESMAN”的员工的姓名、职务和工资。

selectscott.emp.enamescott.emp.sal,scoott.emp.job where job = \18、显示工资大于等于3000的员工姓名、职务和工资。

selectscott.emp.enamescott.emp.sal,scoott.emp.job where sal>3000; 19、显示1982年以后雇佣的员工姓名和雇佣时间。

selectscott.emp.ename,scott.emp.hiredate where hiredate<1982; 20、显示部门编号为10的员工姓名和雇佣时间

selectscott.emp.ename,scott.emp.hiredate where empno=10;

21、显示工资在1000~2000之间(不包括1000和2000)的员工信息。 select *from scott.emp where sal between 1000 and 2000; 22、显示部门10中工资大于1500的员工。

select* from scott.emp where deptno=10 and sal>1500; 23、显示职务为CLERK或MANAGER的员工信息。

select * from scott.emp where job = clerk or job = manager;

24、显示部门10以外的其他部门的员工。

25、显示部门10和部门20中工资小于1500的员工。

select* from scott.emp where deptno = 20 and deptno = 20 and sal<1500; 26、显示名称以“W”开头的员工,并将姓名转换成小写。 select * from scott.emp where ename like 'w%' and lower(ename);

27、显示员工姓名中包含“S”的员工姓名及姓名长度。

selectscott.emp.ename,length(ename) from scott.emp where instr(ename,'S',1,1)>0;

28、显示部门表中部门和所在城市列表,中间以下划线“_”连接,城市名转换成以小写。 selectscott.dept.loc,scott.dept.deptno from scott,dept where substr('loc',1,1);2 select dname||'_'||initcap(loc) from dept; DNAME||'_'||INITCAP(LOC) 29、显示系统的当前日期 selectsysdate from dual;

30、假定当前的系统日期是2013年11月13日,求再过1000天的日期。 select sysdat+1000 as \

31、假定当前的系统日期是2013年11月13日,显示部门10员工的雇佣天数。 selectscott.emp.enam round(sysdate-hiredate)DAYS from scott.emp where empno =10; 32、显示员工姓名和雇佣的星期数

selectempno, ename, round((sysdate - hiredate) / 7) from emp 33、显示从本年1月1日开始到现在经过的天数。

select round(sysdate-round(sysdate,'year')) as 天数 from dual; 34、查询所有员工的奖金,如果奖金没有,用0来替代 selectempno,nvl(comm,0) comm, from scott.emp;

本文来源:https://www.bwwdw.com/article/ood5.html

Top