ImageVerifierCode 换一换
格式:DOCX , 页数:29 ,大小:192.25KB ,
资源ID:11447730      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11447730.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(数据库语句练习及答案.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

数据库语句练习及答案.docx

1、数据库语句练习及答案数据库语句练习及答案(总16页)实验二-、年龄小于20的为豆蔻,20-30之间为弱冠,30-40之间为儿立,40-50之间为不惑,50-60知命, 60-70,为花甲,其他为古稀 select *,case when age20 and age30 and age40 and age50 and age60 and age70 then 花甲 else 古稀end class_agefrom student-查找以_开头的学生的姓名 select *from student where sname like _%-以%开头的学生的姓名, select *from stude

2、nt where sname like %-查找第一个字母是m或者n第二个字母为ykmb的学生的姓名, select *from student where sname like mnykmb%-查找不是以m或者n开头且第二个字母为a到z之间任何一个字母的学生的姓名及具体息, select *from student where sname like mma-z%-查找不是以a到f字母为首字母的学生的信息。 select *from student where sname like a-f%-3、练习各种连接的操作,诸如 join 、left jion、right join、full join

3、以及crossjoin的应用对A、B两个表进行连接。select *from A join B on =select *from A left join B on =select *from A right join B on =select *from A full join B on =select *from A cross join B-讲所有计算机学院的男同学信息显示出来并单独生成一个独立的表,表名字为jsjman。select *into jsjmanfrom studentwhere sex=男 and dept=计算机学院实验二6-【例】 查询员工表中所有员工的姓名和联系电话,

4、可以写为:select 姓名,电话 from Employees-【例】 查询员工表中的所有记录,程序为:select *from Employees-【例】 查询进货表中的所有的生产厂商,去掉重复值,程序为:select distinct 生产厂商 from Goods-【例】 查询进货表中商品名称、单价和数量的前4条记录,程序为:select top 4 商品名称,零售价,数量 from Goods-【例】 使用列的别名,查询员工表中所有记录的员工编号(别名为number),姓名(别名为name)和电话(别名为telephone),select 编号 number,姓名 name, 电话

5、telephone from Employees-【例】 查询各件商品的进货总金额,可以写为:select 商品名称,进货价*数量 from Goods-【例】 在Employees表中查询姓名为王峰的员工的联系电话,程序为:select 姓名,电话 from Employees where 姓名=王峰-【例】 查询笔记本电脑的进货信息,程序为:select *from Goods where 商品名称=笔记本电脑-【例】 查询在2005年1月1日以前销售的商品信息,可以写为:select 商品编号,数量,售出时间 from Sell where 售出时间2005-1-1-【例】 查询进货总金

6、额小于10000元的商品名称,可以写为:select 商品名称 from Goods where 进货价*数量10000-【例】 查询2005年1月1日以前进货且进货价大于1000元的商品,可以写为:select 商品名称 from Goods where 进货时间1000-【例】 查询“李”姓员工的基本信息,可以写为:select *from Employees where 姓名 like 李%-【例】 查询零售价格在2000到3000元之间的所有商品,可以写为:select *from Goods where 零售价=2000 and 零售价90select *from student,s

7、cores where = and sname like刘_ and cn=001 and grade90-练习,交叉并笛卡尔成绩sql语句使用方法,通过 a,b实现。select *from A cross join Bselect * from a intersect select * from b-四、查找以“生”开头,且最后一个为“学”的课程的详细情况select *from student,scores,coursewhere = and = and cname like 生%学-五、查找选号课程的平均成绩、最大成绩、最小成绩,选课的人数select avg(grade)平均成绩 f

8、rom scores where cn=001select max(grade)最大成绩 from scores where cn=001select min(grade)最小成绩 from scores where cn=001select count(cn)选课的人数 from scores where cn=001-六、分别查找选择了某一门课程的学生的人数、分别统计各个系的总人数,分别显示各系男女生总人数,男生人数大于3个的系select cname,count(sn) from course,scores where = group by cnameselect dept,count(

9、sn)人数 from student group by deptselect dept,sex,count(sn) from student group by dept,sex order by deptselect dept,sex,count(sn) from student where sex=男 group by dept,sex having count(sn)3-七、统计计机学院选择了三门以上课程的学生的学号select ,dept,count(cn) from student,scores where = and dept=计算机学院group by ,dept having c

10、ount(cn)3select ,count(cn), from scores,student where =计算机学院 and = group by , having count(cn)3-八、如何通过提供的 student、scores、course三个表生成如下表ok,使用into 语句select ,sname,grade into ok from student,scores,coursewhere = and =-九、在上面新生成的表ok上增加course表中的可课程名字,alter table syy1add cname nvarchar(255)insert into syy1

11、,sname,grade,cname)select ,sname,grade, from student,scores,coursewhere = and =-十、查询各系及学生数,最后求出共有多少系和多少学生select dept,count(sn) from student group by dept compute count(dept),sum(count(sn)-统计各门课程的平均分,要求显示课程名字与代号,具体如下:select ,cname,avg(grade) from course,scores where =group by ,cname order by cn-十一、gr

12、oupby命令复杂应用。-1、统计各个年龄段的人数,具体如下: select class_age= case when age20 and age30 and age40 and age50 and age60 and age70 then 花甲 else 古稀 end ,count(sn) from studentgroup bycase when age20 and age30 and age40 and age50 and age60 and ageorder by gradeselect *from scores where sn=3141201select *from scores

13、where gradeall(select grade from scores where sn=3141201)order by gradeselect *from scoreswhere gradeany(select grade from scores where sn=3141201)order by grade-二、分别查找选择了某一门课程的平均分 select cn,avg(grade) from scores group by cn -三、统计计算机学院选择了三门以上课程的学生的学号 select ,count from scores,student where = and de

14、pt=计算机学院 group by having count3 -四、 对学生的成绩 scores进行等级分类,60以下不及格,90以上良好等 select *, 等级= case when grade60 and grade70 and grade80 and grade90 then 良好 else 优秀endfrom scores-五、 计算学生某门课程与该门课程的平均分之差、与自己所有课程的平均分之差、-查找某个同学的某一门课程小于该门课程的平均成绩的学生的信息-计算学生某门课程与该门课程的平均分之差select ,avgpingjun,abs)与平均分之差from scores x,

15、scores ywhere =group by ,-与自己所有课程的平均分之差select ,avg,abs)from scores x,scores ywhere =group by ,-查找某个同学的某一门课程小于该门课程的平均成绩的学生的信息select ,avg课程平均分from scores x,scores ywhere =group by , having =8-八、统计检索不同客户定购的各种书的总量和所有书的总量、select client_name,book_name,sum(book_number) as 书籍总数 from clients,book ,orderformw

16、here = and = group by client_name,book_name with rollupselect client_name,book_name,book_number 书籍总数 from book,clients,orderformwhere = and = order by client_name compute sum(book_number) select client_name,book_name,book_number 书籍总数 from book,clients,orderformwhere = and = order by client_namecompu

17、te sum(book_number) by client_name实验五-一、查找女生人数大于10个的学院select dept,sex,count(sn) from studentwhere sex=女group by dept,sex having count(sn)10-二、查找选择所有选择001号课程学生的信息及 成绩大于分学生的信息select *from scores,course,studentwhere = and = and =001 and grade90-三、查找所有与3141206号学生选同一门课程同学的学号。select sn from scoreswhere cn

18、=any(select cn from scores where sn=3141206)-四、查找与3141201号学生选课程有相同课程的学生的信息。select ,sname,cname from scores,course,studentwhere = and = and =any(select from scores,coursewhere = and sn=3141201)-五、查找所有比计算机学院学生成绩高的学生信息select ,sname,sex,age,dept,class from scores,studentwhere = and gradeall(select grade

19、 from scores,studentwhere = and dept=计算机学院)select *from studentwhere in(select from scores where all(select from scores,student where = and =计算机学院)-六、对于给定的数据表中的,分别求下列的除法运算,即RS,R1S1,R2S2,scc,stud_coursecourse的结果。select *from Rwhere not exists (select , from s where not in (select from R) and not in (select from R)select *from _R1where not exists(select from _s1 where not in(select from _R1)select * from _R2where not exists(select , from _s2 where not in(select from _R2)

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1