当前位置:文档之家› 简单查询练习题

简单查询练习题

三类简单查询的例题
1) 查询所有信息(全部)
查询所有教师的所有信息
select * from TeacherInformation
查询所有学生的所有信息
select * from StudentInformation
2) 查询部分字段(列上的筛选)
查询学生表中所有学生的姓名和学号。
select SName,SNo from studentInformation


3) 条件查询(查询符合条件的记录)行上的筛选
显示所有男老师的信息
use StudentScoreManager
select * from teacherinformation where tsex='男'

要求完成的查询

查询所有教师的所有信息
select * from TeacherInformation


查询所有学生的所有信息
select * from StudentInformation


查询学生表中所有学生的姓名和学号。
select SName,SNo from studentInformation

--查询学生表中所有学生的姓名和学号。并为列起别名“姓名”,“学号”
select sname as'姓名',sno as'学号'from studentinformation



--查询个人信息,为该用户提供姓名、学号、性别、专业、班级等信息。
select * from studentinformation where sno='07303101'

--管理员用户,根据工号查询教师的所有信息
select * from teacherinformation where tno='0000001'

--管理员用户,查询某系所有教师的所有信息
select * from teacherinformation where tdepartment='计算机工程系'

--查询需要补考人的学号和课程号
select ssno,sscid from studentscore where ssscore between 0 and 59


--班主任用户,查询整班信息。
select * from studentinformation where sno like '073031%'


--管理员用户,查询未分配单位的教师的姓名和工号
select 姓名=tname,工号=tno from teacherinformation where tdepartment is null

--查看成绩表中有那些学生选修了课程,即查看成绩表中的学号。
select distinct ssno from studentscore

--查询需要补考人的学号
select distinct ssno from studentscore where ssscore<60

--任课教师用户,以班为单位查询学生“s07303-15”课程的成绩。
select ssno,'java程序设计'=ssscore from studentscore
where ssno like '073031%'and sscid='s07303-15'

--任课教师用户查询某班学生单科总成绩、平均成绩、最高成绩、最低成绩及参加考试人数。
select 总成绩=sum(ssscore),平均成绩=avg(ssscore),
最高成绩=max(ssscore),最低成绩=min(ssscore),
参加考试人数=count(distinct ssno)
from studentscore where ssno like '073031%'and sscid='s07303-03'

相关主题
文本预览
相关文档 最新文档