1.用一条SQL语句查询出每门课都大于80分的学生姓名
name Course Score
张三 语文 81
张三 数学 75
李四 语文 76
李四 数学 90
王五 语文 81
王五 数学 100
王五 英语 90
create table SC ( Name nvarchar(20), Course nvarchar(20), Score int ) insert into SC values ('张三', '语文', 81), ('张三', '数学', 75), ('李四', '语文', 76), ('李四', '数学', 90), ('王五', '语文', 81), ('王五', '数学', 100), ('王五', '英语', 90) --方法一 select distinct name from SC where name not in (select distinct name from SC where Score<=80) --方法二 select name from SC group by name having min(Score)>80 --方法三 select distinct a.name from SC as a where not exists(select 1 from SC where name=a.name and Score<=80)
2.删除自动编号不同,其他都相同的学生冗余信息
ID StuNO Name CourseNO CourseName Score
1 2005001 张三 0001 数学 69
2 2005002 李四 0001 数学 89
3 2005001 张三 0001 数学 69
create table Student ( ID int, StuNO varchar(10), StuName nvarchar(20), CourseNO varchar(10), CourseName nvarchar(10), Score int ) insert into Student values (1, '2005001', '张三', '0001', '数学', 69), (2, '2005002', '李四', '0001', '数学', 89), (3, '2005001', '张三', '0001', '数学', 69) delete from Student where ID not in ( select min(ID) from Student group by StuNO,StuName,CourseNO,CourseName,Score )
3.一个department表中,只有一个name字段,分别是a,b,c,d对应四个球队,现在四个球队进行比赛,用一条sql语句显示所有可能的比赛组合
create table Department ( name char(1) ) insert into Department values ('a'),('b'),('c'),('d') --a.name>b.name 或 a.name<b.name 都可以 select a.name as A,b.name as B from Department as a,Department as b where a.name>b.name
posted on
浙公网安备 33010602011771号