数据库表的查询操作实践演练(实验三)
继前两次的实验,本次实验以熟练掌握利用select语句进行各种查询操作:单表查询、多表连接及查询、嵌套查询、集合查询等,巩固数据库查询操作。
下面就跟着小编一起练习吧!
在实验一创建并插入数据的表(Student, Course,SC,Teacher,TC)的基础上,完成以下操作。
(1)将教师‘罗莉’的名字改为‘罗莉莉’。
(2)将两个同学(数据自己临时设置,用后即删除)的两门课程的成绩以运行sql程序文件的形式插入score表中。该题用以验证、理解和掌握关系模型的完整性规则;
插入:
insert into Score(sno,cno,grade) values(‘04261007′,’C004′,’79’)
查询:
删除:
(3)求每门课的平均成绩,并把结果存入average表(自行设计并创建);
(
cno CHAR(8),
avscore numeric(5,2),
constraint a1 primary key (cno),
constraint a2 foreign key (cno) references Course(cno),
)
insert into average(cno,avscore)
select distinct cno ,avg(grade) from Score group by cno
(4)将学生“马丽”的年龄改为24;
(5)将所有学生的szipcode属性列值填补上;
(6)将average表中的所有课程的平均成绩置零;
(7)删除average表中的课程号为‘C007’的平均成绩记录;
(8)删除所有average表中平均成绩记录;
(9)建立一个临时学生信息表(tstudent),删除该表中的学号含‘101’的所有学生记录。
Delete from tstudent where Sno like ‘001011%’;
(10)查询全体学生的学号与姓名;
(11)查询全体学生的学号、姓名、所属系;
(12)查询全体学生的详细记录;
(13)查询全体学生的姓名及其年龄;
(14)查询全体学生的姓名、出生年份;
(15)查询所有修过课的学生的学号;
select distinct student.sno from Student,Score where Student.sno=Score.sno and Score.grade>0 ;
(16)查询“计算机系”班全体学生名单;
(17)查询查询所有年龄在23岁以下的学生姓名及其年龄;
(18)查询考试成绩有不及格的学生的学号;
(19)查询年龄在20至22岁之间的学生姓名、系和年龄;
(20)查询年龄不在20至22岁之间的学生姓名、系和年龄;
(21)查询“计算机系”和“电商系”的学生的姓名;
(22)查询既不是“计11”也不是“计61”班的学生的姓名和班级信息;
(23)查询学号为“04262002”的学生的详细情况;
[code]select student.sno,sname,ssex,2014-year(sbirth),sclass,grade from Student,Score where Student.sno=Score.sno and Student.sno=’04262002′;
(24)查询学号以“04262”打头的学生信息;
(25)查询所有姓“张”学生的学号、姓名、性别、年龄;
(26)查询名字中第二个字有“海”字的学生的学号、姓名、性别、年龄;
(27)查询所有不姓“刘”学生的姓名;
(28)查询课程号以“C”开头的最后两个字母为“05”的课程号和课程名;
(29)某些学生选修某门课程后没有参加考试,所以有选修课记录,但没有考试成绩,试查找缺少考试成绩的学生和相应的课程号;
(30)查找全部有成绩记录的学生学号、课程号;
(31)查找“计算机系”年龄在22岁以下的学生学号、姓名;
(32)查找选修了“C001”号课程的学生学号及其成绩,查询结果按分数降序排序;
(33)查询全体学生情况,查询结果按所在系升序排列,对同一系中的学生按年龄降序排列;
(34)查询学生总人数;
(35)查询选修了课程的学生人数;
(36)在所有课程中查询最高分的学生学号和成绩;
(37)查询学习“C001”课程的学生最高分数;
(38)计算各个课程号与相应的选课人数;
(39)查询“计算机系”选修了两门课程以上的学生学号、姓名;
(select Student.sno from Student,Score where
sdept=’计算机系’and Student.sno=Score.sno group by Student.sno having count(cno)>=2);
(40)自然连接student和score表;
(41)使用自身连接查询每一门课程的间接先行课(即先行课的先行课)
(42)使用复合条件连接查询选修“c001”号课程且成绩在90分以上的所有同学;
(43)使用复合条件连接查询每个学生选修的课程名及其成绩;
(44)查询选修了全部课程的学生;
(45)查询所有选修了C001号课程的学生学号、姓名;
(46)查询选修了课程C001或C007的学生学号、姓名;
[code]select student.sno,sname,cno from student,Score where student.sno=Score.sno and cno in (‘C001′,’C007’);
[/code]
(47)查询“计算机系”的学生及年龄不大于23岁的学生;
(48)查询既选修了课程C001又选修了课程C007的所有学生学号、姓名;
(49)查询选修了课程名为“数据库原理”的学生的学号、姓名、性别、年龄;
(50)查询其他班中比“计算机系”所有学生年龄都小的学生名单;
(51)查询与“夏天”在同一个系学习的学生学号、姓名、性别、年龄;
(52)建立“计算机系”学生的视图1;
as select sno,sname,ssex,sbirth,sclass from student where sclass=’13z网络’
(53)建立“计算机系”学生的视图2,并要求进行修改与插入时,仍须保证该视图只有“计算机系”班学生;
as select sno,sname,ssex,sbirth,sclass from student where sclass=’13z网络’ with check option;
(54)建立“计算机系”选修了“C001”课程的学生的视图,定义视图名为“v_cs_C001_student1”;
as select student.sno,sname,ssex,sbirth,sclass from Student ,Score where
student.sno=Score.sno and sclass=’13z网络’ and cno=’C001′;
(55)建立“计算机系”班选修了“C001”课程且成绩在90分以上的学生的视图,定义视图名为“cs_c001_student2”;
as
select student.sno,sname ,ssex,sbirth,sclass,cno from student,Score where
student.sno=Score.sno and cno=’C001′ and sclass=’13z网络’and student.sno in (select student.sno from student,Score where student.sno=Score.sno and grade>90)
(56)定义一个反映学生年龄的视图,定义视图名为“v_birth_student”;
as
select sno,sname,2014-year(sbirth) age from student
(57)将学生表中所有女生记录定义为一个视图,视图名为“v_female_student”;
as
select * from student where ssex=’女’;
(58)将学生的学号及其平均成绩定义为一个视图,视图名为“v_average_student”;
as
select sno,avg(grade) avscore from Score group by sno;
(59)在“计算机系”学生视图中找出年龄小于22岁的学生;
(60)利用视图查询“计算机系”选修了“C001”课程的学生;
(61)通过(52)中的“计算机系”视图修改某个学生的名字;
(62)通过(53)中的“计算机系”视图,插入一个新学生记录。
(63)通过(53)中的“计算机系”视图,删除一个学生记录。
实验课结束了,相信通过本节课的实践操作,小伙伴们都对数据库表的操作有了更进一步的了解。
以上就是查询数据库表的基本操作,几乎涵盖了各种查询操作所遇到的情况,值得大家亲自操作一下,相信对大家的学习有所帮助。
- MySQL学习笔记3:表的基本操作介绍
- 单个select语句实现MySQL查询统计次数
- sql查询出各科成绩最好的学生信息
- mysql查询昨天 一周前 一月前 一年前的数据
- mysql查询今天、昨天、近7天、近30天、本月、上一月的SQL语句
- MySql查询时间段的方法
- MySQL查询和修改auto_increment的方法
- 一个优化MySQL查询操作的具体案例分析
- MySQL查询倒数第二条记录实现方法
- 50条SQL查询技巧、查询语句示例
- SQL查询出表、存储过程、触发器的创建时间和最后修改时间示例
- 大幅优化MySQL查询性能的奇技淫巧
- SQL大量数据查询的优化及非用like不可时的处理方案
- 如何使用MySQL查询某个列中相同值的数量统计
- SQL如何实现MYSQL的递归查询
- 数据库表的创建、管理和数据操作(实验一)
- 数据库表的查询操作(实验二)
相关文章
-
Sqlserver中char,nchar,varchar与Nvarchar的区别分析
Sqlserver中char,nchar,varchar与Nvarchar的区别分析,使用sqlserver的朋友可以参考下。2011-08-08
SQLServer 数据库变成单个用户后无法访问问题的解决方法
今天不知怎么点错了东西,SQLServer中的一个数据库变成单用户了,而且无法访问,下面是解决方法,有需要的朋友可以参考一下2013-10-10
var ourl = “”;
/*更多导航*/
$(“#nav p”).hover(function() {
$(this).addClass(“hover”)
}, function() {
$(this).removeClass(“hover”)
});
if (top.location != self.location) top.location = self.location;
var varwindow = $(window);
$(‘#content’).find(‘img’).each(function() {
var img = this;
if (img.width >= 800 && !$(this).hasClass(“nohref”)) {
img.style.width = “800px”;
img.style.height = “auto”;
}
});
function sideFixed() {
var scrolltop = document.body.scrollTop || document.documentElement.scrollTop;
if (ww > 440) {
if (550 <= scrolltop){
$('#right-share').slideDown();
} else {
$('#right-share').slideUp();
}
if(suoyin=='ok'&&typeof cataloguetop=='number'){
if (cataloguetop = fixedTop + 330) {
var h1 = parseInt($(‘#content’).children(‘.main’).height());
$(‘.rFixedBox’).css({
‘position’: ‘fixed’,
‘top’: 0
});
} else {
$(‘.rFixedBox’).css({
‘position’: ‘static’,
‘top’: 0
});
}
/* return true;*/
/*右侧快捷菜单*/
sideFixed();
});
$(window).scroll();
$(‘.rshare-weixin’).hover(function() {
$(‘#weixin-code’).removeClass(‘hide’);
}, function() {
$(‘#weixin-code’).addClass(‘hide’);
});
/*二维码*/
$(‘#right-share .rshare-top’).on(‘click’, function() {
$(‘html,body’).animate({
‘scrollTop’: 0
}, 500);
});
function show_suoyin() {
var vww = 0;
vww = varwindow.width();
if (suoyin == “ok”) {
if (vww > 1600) {
var catell = document.getElementById(“CatelogList”);
if (vww < 1920) {
catell.style.width = (((vww – 1200) / 2) – 20) + "px";
} else {
catell.style.width = "340px";
}
if (!window.suoyinobj) {
window.suoyinobj = new katelog({
contentEl: 'content',
catelogEl: 'CatelogList',
linkClass: 'AutoCatelogLink',
linkActiveClass: 'CatelogActive',
supplyTop: 20,
selector: ['h2', 'h3', 'h4'],
active: function(el) {
//console.log(el);
}
});
}
} else {
window.suoyinobj = null;
//GenerateContentList();
}
}
}
SyntaxHighlighter.autoloader(
'applescript /jslib/syntaxhighlighter/scripts/shBrushAppleScript.js',
'actionscript3 as3 /jslib/syntaxhighlighter/scripts/shBrushAS3.js',
'bash shell /jslib/syntaxhighlighter/scripts/shBrushBash.js',
'coldfusion cf /jslib/syntaxhighlighter/scripts/shBrushColdFusion.js',
'cpp c /jslib/syntaxhighlighter/scripts/shBrushCpp.js',
'obj-c objc /jslib/syntaxhighlighter/scripts/shBrushObjC.js',
'c# c-sharp csharp /jslib/syntaxhighlighter/scripts/shBrushCSharp.js',
'css /jslib/syntaxhighlighter/scripts/shBrushCss.js',
'delphi pascal /jslib/syntaxhighlighter/scripts/shBrushDelphi.js',
'diff patch pas /jslib/syntaxhighlighter/scripts/shBrushDiff.js',
'erl erlang /jslib/syntaxhighlighter/scripts/shBrushErlang.js',
'groovy /jslib/syntaxhighlighter/scripts/shBrushGroovy.js',
'haxe hx /jslib/syntaxhighlighter/scripts/shBrushHaxe.js',
'java /jslib/syntaxhighlighter/scripts/shBrushJava.js',
'jfx javafx /jslib/syntaxhighlighter/scripts/shBrushJavaFX.js',
'js jscript javascript /jslib/syntaxhighlighter/scripts/shBrushJScript.js',
'perl pl /jslib/syntaxhighlighter/scripts/shBrushPerl.js',
'php /jslib/syntaxhighlighter/scripts/shBrushPhp.js',
'text plain /jslib/syntaxhighlighter/scripts/shBrushPlain.js',
'py python /jslib/syntaxhighlighter/scripts/shBrushPython.js',
'ruby rails ror rb /jslib/syntaxhighlighter/scripts/shBrushRuby.js',
'scala /jslib/syntaxhighlighter/scripts/shBrushScala.js',
'sql /jslib/syntaxhighlighter/scripts/shBrushSql.js',
'vb vbnet /jslib/syntaxhighlighter/scripts/shBrushVb.js',
'ps powershell /jslib/syntaxhighlighter/scripts/shBrushPowerShell.js',
'xml xhtml xslt html /jslib/syntaxhighlighter/scripts/shBrushXml.js'
);
SyntaxHighlighter.all();
(function() {
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
} else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);jbLoader();jbLoader(true);
if (‘undefined’ == typeof(window.Viewer)) {
document.write(unescape(“%3Cscript src=’/skin/js/viewer.min.js’ type=’text/javascript’%3E%3C/script%3E”));
}
var viewer = new Viewer(document.getElementById(‘content’));
(function(){
var src = (document.location.protocol == “http:”) ? “http://js.passport.qihucdn.com/11.0.1.js?d182b3f28525f2db83acfaaf6e696dba”:”https://jspassport.ssl.qhimg.com/11.0.1.js?d182b3f28525f2db83acfaaf6e696dba”;
document.write(”);
})();
{
“@context”: “https://ziyuan.baidu.com/contexts/cambrian.jsonld”,
“@id”: “https://www.jb51.net/article/70770.htm”,
“appid”: “1549322409310619”,
“title”: “数据库表的查询操作实践演练(实验三)”,
“description”: “这篇文章主要对数据库表的查询操作进行实践演练,针对实验一和实验二涉及到的内容进一步深入学习,进一步理解关系运算,巩固数据库的基础知识,感兴趣的小伙伴可以参考一下”,
“pubDate”: “2015-08-07T15:41:41”,
“upDate”: “2015-08-07T15:41:41”
}
文章来源于互联网:数据库表的查询操作实践演练(实验三)
原创文章,作者:admin,如若转载,请注明出处:https://www.aliyunsolution.com/3670.html
最新评论