SQL的练习,求答案!!!

例1 从员工表中查询员工姓名和工资
例2 查询所有的供应商信息
例3 查询顾客表的前面七行
例4查询顾客表前面5%的行
例5 从员工表中查询不相同的部门号
例6 查询员工增加15%的工资后的工资数
例7 从员工表中查询员工的周岁年龄,并在年龄前加说明字符串‘员工的周岁年龄是:’
例8 从员工表中查询员工姓名和工资,用三种方式加别名
例9 查询客户表中客户的个数
例10 查询员工的最高和最低工资
例11 把供应商表的供应商名称和联系人送到另一个表中
例12 查询员工'李立三'的工资
例13 查询工资大于3500有哪些员工
例14 查询工资大于3500的男员工有哪些
例15 *查询符合某个范围内的数据*/查询库存量在1000-3000的商品
例16/*查询中使用关键字IN,*/ 查询员工号13、17得到的订单

例17 查询工资在3000-4000的员工姓名和工资
例18查询库存量在1000-3000的商品名称
例19 在Sell_order中,查询员工编号为2、4和9的员工接受订单信息。
例 20 查询中使用关键字IN,查询2、4和9号以外的其他员工得到的订单
例5.21 查询中使用关键字LIKE*,查询姓吴的员工
例5.22 查询中使用关键字LIKE查询姓黄和姓刘的员工
例5.23 查询中使用关键字LIKE, 查询姓赵并且姓名为两个字的员工
例5.24 查询中使用关键字LIKE, 查询不姓王的员工
例5.25 使用null或not null查询没有订单的员工号
我是初学者!也有自己做,但是很迷茫!

有一些类似的题看看吧 一定有帮助
实验一
练习1、请查询表DEPT中所有部门的情况。
select * from dept;

练习2、查询表DEPT中的部门号、部门名称两个字段的所有信息。
select deptno,dname from dept;

练习3、请从表EMP中查询10号部门工作的雇员姓名和工资。
select ename,sal from emp where deptno=10;

练习4、请从表EMP中查找工种是职员CLERK或经理MANAGER的雇员姓名、工资。
select ename,sal from emp where job='CLERK' or job='MANAGER';

练习5、请在EMP表中查找部门号在10-30之间的雇员的姓名、部门号、工资、工作。
select ename,deptno,sal,job from emp where deptno between 10 and 30;

练习6、请从表EMP中查找姓名以J开头所有雇员的姓名、工资、职位。
select ename,sal,job from emp where ename like 'J%';

练习7、请从表EMP中查找工资低于2000的雇员的姓名、工作、工资,并按工资降序排列。
select ename,job,sal from emp where sal<=2000 order by sal desc;

练习8、请从表中查询工作是CLERK的所有人的姓名、工资、部门号、部门名称以及部门地址的信息。
select ename,sal,emp.deptno,dname,loc from emp,dept where emp.deptno=dept.deptno and job=’CLERK’;

练习9、查询表EMP中所有的工资大于等于2000的雇员姓名和他的经理的名字。
select a.ename,b.ename from emp a,emp b where a.mgr=b.empno(+) and a.sal>=2000;

练习10、在表EMP中查询所有工资高于JONES的所有雇员姓名、工作和工资。
select ename,job,sal from emp where sal>(select sal from emp where ename=’JONES’);

练习11、列出没有对应部门表信息的所有雇员的姓名、工作以及部门号。
select ename,job,deptno from emp where deptno not in (select deptno from dept);

练习12、查找工资在1000~3000之间的雇员所在部门的所有人员信息
select * from emp where deptno in (select distinct deptno from emp where sal between 1000 and 3000);

练习13、雇员中谁的工资最高。
select ename from emp where sal=(select max(sal) from emp);
select ename from (select * from emp order by sal desc) where rownum<=1;

*练习14、雇员中谁的工资第二高(考虑并列第一的情况,如何处理)。
select ename,sal from (select ename ,sal from emp where sal<(select max(sal) from emp) order by sal desc) where rownum<=1;
实验二
1. 查询所有雇员的姓名、SAL与COMM之和。
select ename,sal+nvl(comm,0) “sal-and-comm” from emp;

2. 查询所有81年7月1日以前来的员工姓名、工资、所属部门的名字
select ename,sal,dname from emp,dept where emp.deptno=dept.deptno and hiredate<=to_date(‘1981-07-01’,’yyyy-mm-dd’);

3. 查询各部门中81年1月1日以后来的员工数
select deptno,count(*) from emp where hiredate>=to_date(‘1981-01-01’,’yyyy-mm-dd’) group by deptno;

4. 查询所有在CHICAGO工作的经理MANAGER和销售员SALESMAN的姓名、工资
select ename,sal from emp where (job=’MANAGER’ or job=’SALES’) and deptno in (select deptno from dept where loc=’CHICAGO’);

5. 查询列出来公司就职时间超过24年的员工名单
select ename from emp where hiredate<=add_months(sysdate,-288);

6. 查询于81年来公司所有员工的总收入(SAL和COMM)
select sum(sal+nvl(comm,0)) from emp where to_char(hiredate,’yyyy’)=’1981’;

7. 查询显示每个雇员加入公司的准确时间,按××××年××月××日 时分秒显示。
select ename,to_char(hiredate,'yyyy-mm-dd hh24:mi:ss') from emp;

8. 查询公司中按年份月份统计各地的录用职工数量
select to_char(hiredate,'yyyy-mm'),loc,count(*) from emp,dept
where emp.deptno=dept.deptno group by to_char(hiredate,'yyyy-mm'),loc;

9. 查询列出各部门的部门名和部门经理名字
select dname,ename from emp,dept where emp.deptno=dept.deptno and job=’MANAGER’;

10. 查询部门平均工资最高的部门名称和最低的部门名称
select dname from dept where deptno=(select deptno from (select deptno from emp group by deptno order by avg(sal) ) where rownum<=1)
union all select dname from dept where deptno=(select deptno from (select deptno from emp group by deptno order by avg(sal) desc ) where rownum<=1);

11. *查询与雇员号为7521员工的最接近的在其后进入公司的员工姓名
select ename from (select ename from
(select ename from emp where hiredate>(select hiredate from emp where empno=7521) order by hiredate ) where rownum<=1)
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-11-21
/*创建Moonfox_db数据库*/
use master
if exists(select * from sysdatabases where name='Moonfox_db')
drop database Moonfox_db
create database Moonfox_db
on
(
name='Moonfox_db_data',
filename='D:\Visual Studio 2008 & Sql server 2005\Sql server\Moonfox_db.mdf',
size=10,
filegrowth=2MB
)
log on
(
name='Moonfox_db_log',
filename='D:\Visual Studio 2008 & Sql server 2005\Sql server\Moonfox_db.ldf',
size=5,
filegrowth=20%
)/*创建Department表*/
use Moonfox_db
if exists(select * from sysobjects where name='Department')
drop table Department
create table Department
(
DID int identity (1,1)primary key,--部门编号,主键
Dname nvarchar(20),--部门名称
Address nvarchar(50),--部门地址
Photo decimal(12,0),--电话
)/*创建Employee表*/
use Moonfox_db
if exists(select * from sysobjects where name='Employee')
drop table Employee
create table Employee
(
EID int identity (1,1)primary key,--职工编号,主键
Ename varchar(10),--职工名
Gender nchar(2) check(Gender='男' or Gender='女'),--性别,添加限制
Position nvarchar(10) check(Position='员工' or Position='组长' or Position='经理'),--职务,添加限制
Address nvarchar(50),--家庭地址
DID int,--部门编号,外键
foreign key(DID) references Department(DID)--外键约束
)
/*创建Care表*/
use Moonfox_db
if exists(select * from sysobjects where name='Care')
drop table Care
create table Care
(
CID int identity (1,1)primary key,--保健卡编号,主键
EID int,--职工号,外键
foreign key(EID) references Employee(EID),--外键约束
CheckDate datetime,--检查身体日期
PhysicalCondition nvarchar(4) check(PhysicalCondition='一般' or PhysicalCondition='差' or PhysicalCondition='好'),--健康状况
)
/*创建Care表约束*/
alter table Care
add
constraint DF_CheckDate default(getdate()) for CheckDate--缺省,默认净时间为当前计算机时间 路径自己修改,试图自己做,选择语句自己写。我该睡觉了,抱歉,你试着在sql server中运行下,我等着休息,也不知道写的有没有错误,没时间帮你写省下的了。不急着用的话我明天帮你写吧。
第2个回答  2011-10-11
= = 够恶心的....
第3个回答  2011-10-11
我擦,你自己去csdn找啊,oracle课后习题答案。本回答被提问者采纳
第4个回答  2011-10-11
表名和表段呢……

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网