create database Example   创建数据库
create table Student      学生表
(
   StdNo int identity(200301,1) primary key  not null,
   Sname varchar(20) not null,
   Sspec varchar(10) not null,
   Class char(4) not null
)
create table Grade   成绩表
(
   StdNo int  not null,
   CouseNo char(2) not null,
   grade  real  null
)
create table Couse   课程表
(
  CouseNo char(2)primary key not null,
  CouseName char(50) unique null
)
alter table  Grade     向成绩表中加约束
add constraint cn_grade
check
(grade>=0 and grade<=100)

alter table Grade   向成绩表中加外键
add constraint pk_CouseNo
foreign key (CouseNo)references Couse(CouseNo)

alter table Grade    向成绩表中加外键
add constraint fk_StdNo
foreign key (StdNo)references Student(StdNo)

检索“Grade表”中StdNo字段的数据,要求查询结果中不包含重复记录
select distinct StdNo from Grade 

从Student表中查询姓名中第二个字是“小”的学生
select* from Student where Sname like '_小%'

从Student表中查找姓王、姓李和姓刘的学生记录
select*from Student where Sname like '王%'or Sname like '李%'or Sname like'刘%'

找出没有成绩的学生的信息
select Student.*,Grade.CouseNo,Grade.grade from Student inner join Grade on Grade.grade is null

统计Grade表中记录学生总数
select  count(distinct StdNo) as StudentNumber
from Grade


3 、select distinct Class,CouseNo, avg(grade) as 平均成绩 from Grade,Student where Student.StdNo=Grade.StdNo
group by CouseNo,Class
order by avg(grade) desc,Class asc