SQL Server中是不区分大小写的
select *
from Student
go
select Sno,Sname
from Student
go
select Sno,Sname,Sdept
from Student
go
select Distinct Sno
from SC
go
select Sno,SageAge
from Student
go
select Count(*)人数
from Student
go
select Count(distinct Sno)人数
from SC
go
select SUM(Grade)总分,
AVG(Grade)平均分,
MAX(Grade)最高分,
MIN(Grade)最低分
from SC
where Sno='201815121'
go
select Sname
from Student
where Sdept='CS'
go
select Sname,SageBirthday
from Student
where Sage <20
go
(1).select Sname
from Student
where Sage between 18 and 19
go
(2).select Sname
from Student
where Sage>=18 and
Sage<=19
go
(1).select Sname,SageBirthday
from Student
where Sage<18 or
Sage>19
go
(2).select Sname,SageBirthday
from Student
where Sage not between 18 and 19
go
13 、 查询年龄不是18和19的学生的姓名和年龄 (两种方法)
(1).select Sname,SageBirthday
from Student
where Sage !=18 and Sage !=19
go
(2).select Sname,SageBirthday
from Student
where Sage <>18 and Sage <>19
go
14 、 查询信息系(IS)、数学系(MA)学生的姓名和性别
select Sname,Ssex
from Student
where Sdept IN('IS','MA')
go
15 、 查询所有不姓刘的学生姓名。
select Sname
from Student
where Sname NOT LIKE '刘%'
go
16 、 查询没有先行课的课程号和课程名
select Cno,Cname
from Course
where Cpno is null
go
17 、 显示年龄大于18岁的男女生人数,结果降序列
select Ssex, COUNT(Ssex)人数
from student
where Sage> 18
group by Ssex
order by COUNT(Ssex) desc
go
18 、 查询选修了2门以上课程的学生学号
select Sno
from SC
group by Sno
Having COUNT(*)>2
go
19 、 查询学生的学号、姓名、课程号和成绩
select distinct Student.Sno,Sname,Cno,Grade
from Student,SC
where Student.Sno=SC.sno
go
20 、 查询每一门课的间接先修课(即先修课的先修课)
select First.Cno,Second.Cpno
from Course First,Course Second
where First.Cpno = Second.Cno
go
21 、 查询除刘晨外其他与“刘晨”同龄的学生。
select Sname
from Student
where Sage
in(
select Sage
from Student
where Sname='刘晨'
)
and Sname <>'刘晨'
go
22 、 找出每个学生超过他选修课程平均成绩的课程号。
select Sno,Cno
from SC x
where
Grade>(
select AVG(Grade)
from SC y
where y.Sno=x.Sno
)
go
23 、 查询其他系中比计算机科学某一学生年龄小的学生姓名和年龄
select sname, Sage
from student
where Sage
<Any(
select Sage
from student
where sdept='CS'
)
and sdept<>'CS'
go
24 、 查询其他系中比计算机科学系所有学生年龄都小的学生姓名及年龄。
select student.sname, Sage
from student
where Sage
<(
select min (Sage)
from student
where sdept='CS'
)
and sdept<>'CS'