使用SQL语句查询学生数据库中学生信息 | 您所在的位置:网站首页 › 要查询information表中姓张的学生情况可用命令 › 使用SQL语句查询学生数据库中学生信息 |
SQL语句不区分大小写 调用数据库(数据库创建见上一篇文章) use STU_Information go1.查询各位学生的学号、班级和姓名 --1.查询各位学生的学号、班级和姓名 select SNo,ProClass,SN from Stu2.查询课程的全部信息 --2.查询课程的全部信息 select * from Course3.查询数据库中有哪些专业班级distinct查询的结果中去掉重复行 --3.查询数据库中有哪些专业班级 select distinct ProClass from Stu --distinct查询的结果中去掉重复行4.查询学时数大于60的课程信息 比较运算符后面的数字不加单引号 --4.查询学时数大于60的课程信息 select * from Course where CHour>60 --比较运算符后面的数字不加单引号5.查询在1986年出生的学生学号、姓名和出生日期 --5.查询在1986年出生的学生学号、姓名和出生日期 select SNo,SN,Birthday from Stu where Birthday between '1986-1-1' and '1986-12-31' --select SNo,SN,Birthday from Stu where Birthday like '1986%'--必须字符型才可以 %匹配任意多个字符串 --select * from Stu where datename(year,Birthday) ='1986'6.查询三次作业成绩都在80分以上的学号、课程号 --6.查询三次作业成绩都在80分以上的学号、课程号 select SNo,CNo from StuWork where WScore1>=80 and WScore2>=80 and WScore3>=807.查询姓张的学生的学号、姓名和专业班级 select SNo,SN,ProClass from Stu where SN like '张%' --7.查询姓张的学生的学号、姓名和专业班级 select SNo,SN,ProClass from Stu where SN like '张%'8.查询05级的男生信息 --8.查询05级的男生信息 select * from Stu where ProClass like '%05'9.查询没有作业成绩的学号和课程号 --9.查询没有作业成绩的学号和课程号 select SNo,CNo from StuWork where WScore1 is null or WScore2 is null or WScore3 is null10.查询学号为0538的学生的作业1总分 10.查询学号为0538的学生的作业1总分 select sum(WScore1) from StuWork where SNo=0538 select sum(WScore1) as Score1_Sum from StuWork where SNo=0538 --有列名11.查询选修了K001课程的学生人数 --11.查询选修了K001课程的学生人数 select count(distinct SNo) as 选修人数 from StuWork where CNo='K001' --有列名 distinct消除重复行 select count(distinct SNo) from StuWork where CNo='K001'12.查询数据库中共有多少个班级 --12.查询数据库中共有多少个班级 select count(distinct ProClass) from Stu select count(distinct ProClass) as 班级总数 from Stu --有列名--13.查询选修三门以上(含三门)课程的学生的学号和作业1平均分、作业2平均分和作业3平均分 --13.查询选修三门以上(含三门)课程的学生的学号和作业1平均分、作业2平均分和作业3平均分 select SNo,count(*) as 选修课数目, round (avg(WScore1),2) as 作业1平均分,round (avg(WScore2),2) as 作业2平均分,round(avg(WScore3),2) as 作业3平均分 from StuWork group by SNo having count(*)>=3 --round (avg(WScore1),2) 作业1平均分 保留小数点后2位14.查询于兰兰的选课信息,列出学号、姓名、课程号(使用两种连接查询的方式) --14.查询于兰兰的选课信息,列出学号、姓名、课程号(使用两种连接查询的方式) select Stu.SNo,Stu.SN,Course.CN from Stu,Course,StuWork where StuWork.CNo=Course.CNo and StuWork.SNo=Stu.SNo and Stu.SN='于兰兰' select Stu.SNo,Stu.SN,Course.CN from Course inner join StuWork on Course.CNo=StuWork.CNo inner join Stu on StuWork.SNo=Stu.SNo where Stu.SN='于兰兰' select distinct Stu.SNo,Stu.SN,Course.CN from Stu join StuWork on Stu.SNo=StuWork.SNo join Course on StuWork.CNo=Course.CNo where Stu.SN='于兰兰'-------------------------------------------------------------------------------------------------------------------------------- |
CopyRight 2018-2019 实验室设备网 版权所有 |