数据库语句练习及答案.doc
文本预览下载声明
实验二
--1、年龄小于20的为豆蔻,20-30之间为弱冠,30-40之间为儿立,40-50之间为不惑,50-60知命, 60-70,为花甲,其他为古稀
select *,
case
when age=20 then 豆蔻
when age20 and age30 then 弱冠
when age30 and age40 then 儿立
when age40 and age50 then 不惑
when age50 and age60 then 知命
when age60 and age70 then 花甲
else 古稀
end class_age
from student
--查找以_开头的学生的姓名
select *from student
where sname like [_]%
--以%开头的学生的姓名,
select *from student
where sname like [%]%
--查找第一个字母是m或者n第二个字母为ykmb的学生的姓名,
select *from student
where sname like [mn][ykmb]%
--查找不是以m或者n开头且第二个字母为a到z之间任何一个字母的学生的姓名及具体息,
select *from student
where sname like [^mm][a-z]%
--查找不是以a到f字母为首字母的学生的信息。
select *from student
where sname like [^a-f]%
--3、练习各种连接的操作,诸如 join 、left jion、right join、full join以及crossjoin的应用对A、B两个表进行连接。
select *from A join B on A.Field_k=B.Field_k
select *from A left join B on A.Field_k=B.Field_k
select *from A right join B on A.Field_k=B.Field_k
select *from A full join B on A.Field_k=B.Field_k
select *from A cross join B
--讲所有计算机学院的男同学信息显示出来并单独生成一个独立的表,表名字为jsjman。
select *into jsjman
from student
where sex=男 and dept=计算机学院
实验二6
--【例4.1】 查询员工表中所有员工的姓名和联系电话,可以写为:
select 姓名,电话 from Employees
--【例4.2】 查询员工表中的所有记录,程序为:select *from Employees
--【例4.3】 查询进货表中的所有的生产厂商,去掉重复值,程序为:
select distinct 生产厂商 from Goods
--【例4.4】 查询进货表中商品名称、单价和数量的前4条记录,程序为:
select top 4 商品名称,零售价,数量 from Goods
--【例4.5】 使用列的别名,查询员工表中所有记录的员工编号(别名为number),姓名(别名为name)和电话(别名为telephone),
select 编号 number,姓名 name, 电话 telephone from Employees
--【例4.6】 查询各件商品的进货总金额,可以写为:select 商品名称,进货价*数量 from Goods
--【例4.7】 在Employees表中查询姓名为王峰的员工的联系电话,程序为:
select 姓名,电话 from Employees where 姓名=王峰
--【例4.8】 查询笔记本电脑的进货信息,程序为:
select *from Goods where 商品名称=笔记本电脑
--【例4.9】 查询在2005年1月1日以前销售的商品信息,可以写为:
select 商品编号,数量,售出时间 from Sell where 售出时间2005-1-1
--【例4.10】 查询进货总金额小于10000元的商品名称,可以写为:
select 商品名称 from Goods where 进货价*数量10000
--【例4.11】 查询2005年1月1日以前进货且进货价大于1000元的商品,可以写为:
select 商品名称 from Goods where 进货时间2005-1-1 and 进货价1000
--【例4.12】 查询“李”姓员工的基本信息,可以写为:
select *from Employees
显示全部