您的位置:首页 > 运维架构

常用语句(四)select top ... ... from ... where ... not in(select top ... ... from ...)、AVG()

2013-04-14 15:44 495 查看
/*
alter table score drop constraint FK_student
go
alter table student drop constraint PK_student
go
alter table score drop constraint PK_score
go
*/
select top (6-4+1) * from student st1 where st1.sno not in(select top (4-1) st2.sno from student st2)
go
alter table student add constraint PK_student primary key(sno)
go
alter table course add constraint PK_course primary key(cno)
go
alter table score add constraint FK_score1 foreign key(sno) references student(sno)
go
alter table score add constraint FK_score2 foreign key(cno) references course(cno)
go
/*
*/
select sname from student st where st.sno in(select sno from score sc where st.sno=sc.sno and sc.cno=(select cno from course where cname like '%英语%') and grade is not null)
go
select sname,age from student st inner join score sc on st.sno=sc.sno where cno=(select cno from course where cname like '%英语%') and sc.grade>(select AVG(grade) from score where cno=(select cno from course where cname like '%英语%')) group by sname,age
go
select AVG(grade) from score where cno=(select cno from course where cname like '%英语%')
go
/*
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐