当阳市人力资源和社会保障局,青山不老课件,丰城政府网
Student(S#,Sname,Sage,Ssex)学生表 S#:学号 Sname:学生姓名 Sage:学生年龄 Ssex:学生性别 Course(C#,Cname,T#)课程表 C#:课程编号 Cname:课程名称 T#:教师编号 SC(S#,C#,score)成绩表 S#:学号 C#:课程编号 score:成绩 Teacher(T#,Tname)教师表 T#:教师编号: Tname:教师名字
问题:
select a.S# from (select S#,score from SC where C#='001')a, (select s#,score from SC where c#='002')b Where a.score>b.score and a.s# = b.s#;
select S#, avg(score) from sc group by S# having avg(score)>60
select student.S#, student.Sname, count(sc.C#), sum(score) from student left outer join SC on student.S# = SC.S# group by Student.S#, Sname
select count(distinct(Tname)) from teacher where tname like '李%';
select student.S#, student.Sname from Student where S# not in (select distinct(SC.S#) from SC,Course,Teacher where sc.c#=course.c# AND teacher.T#=course.T# AND Teahcer.Tname ='叶平');
select S#,Sname from Student where S# in (select S# from SC ,Course ,Teacher where SC.C#=Course.C# and Teacher.T#=Course.T# and Teacher.Tname='叶平' group by S# having count(SC.C#)=(select count(C#) from Course,Teacher where Teacher.T#=Course.T# and Tname='叶平'));
select Student.S#,Student.Sname from Student,SC where Student.S#=SC.S# and SC.C#='001'and exists( Select * from SC as SC_2 where SC_2.S#=SC.S# and SC_2.C#='002');
Select S#,Sname from (select Student.S#,Student.Sname,score , (select score from SC SC_2 where SC_2.S#=Student.S# and SC_2.C#='002') score2 from Student,SC where Student.S#=SC.S# and C#='001') S_2 where score2 < score;
select S#, sname from student where s# not in (select student.s# from student, sc where s.s# = sc.s# and score>60);
select student.s#, student.sname from student, sc where student.s#=sc.s# group by student.s#, student.sname having count(c#)<(select count(c#) from course);
select s#, Sname from Student, SC where student.s# = sc.s# and c# in (select c# from SC where s#='1001');
select distinct sc.s# , sname from student, sc where student.s#=sc.s# and c# in (select C# from sc where s#='001');
Update Sc Set Score=(Select Avg(s2_Score) From sc s2 Where s2.c#=sc.c#) Where c# IN (Select c# From sc cs INNER JOIN Teacher tc ON cs.t#=tc.t# WHERE tname ='叶平')
select s# from sc where c# in (select c# from sc where s#='1002') group by s# having count(*)= (select count(*) from sc where s#='1002');
delect sc from course, Teacher where course.c#=sc.c# and course.t#=teacher.t# and tname='叶平';
Insert SC select S#,'002', (Select avg(score) from SC where C#='002') from Student where S# not in (Select S# from SC where C#='002');
select s# as 学生ID, (select score from sc where sc.s#=t.s# and c#='004') as 数据库, (select score from sc where sc.s#=t.s# and c#='001') as 企业管理, (select score from sc where sc.s#=t.s# and c#='006') as 英语, count(*) as 有效课程数, avg(t.score) as 平局成绩 from sc as t group by s# order by avg(t.score)
select L.c# as 课程ID, L.score as 最高分, R.score as 最低分 from sc L, sc R where L.c# = R.c# and L.score = (select max(IL.score) from sc IL, student as IM where L.c#=IL.c# and IM.s#=IL.s# group by IL.c#) and R.score = (select min(IR.score) from sc as IR where R.c#=IR.c# group by IR.c#);
SELECT t.C# AS 课程号, max(course.Cname)AS 课程名, isnull(AVG(score),0) AS 平均成绩, 100 * SUM(CASE WHEN isnull(score,0)>=60 THEN 1 ELSE 0 END)/COUNT(*) AS 及格百分数 FROM SC T,Course where t.C#=course.C# GROUP BY t.C# ORDER BY 100 * SUM(CASE WHEN isnull(score,0)>=60 THEN 1 ELSE 0 END)/COUNT(*) DESC
SELECT max(Z.T#) AS 教师ID, MAX(Z.Tname) AS 教师姓名, C.C# AS 课程ID, AVG(Score) AS 平均成绩 FROM SC AS T,Course AS C ,Teacher AS Z where T.C#=C.C# and C.T#=Z.T# GROUP BY C.C# ORDER BY AVG(Score) DESC
SELECT SC.C# as 课程ID, Cname as 课程名称, SUM(CASE WHEN score BETWEEN 85 AND 100 THEN 1 ELSE 0 END) AS [100 - 85] , SUM(CASE WHEN score BETWEEN 70 AND 85 THEN 1 ELSE 0 END) AS [85 - 70], SUM(CASE WHEN score BETWEEN 60 AND 70 THEN 1 ELSE 0 END) AS [70 - 60], SUM(CASE WHEN score < 60 THEN 1 ELSE 0 END) AS [60 -] FROM SC,Course where SC.C#=Course.C# GROUP BY SC.C#,Cname;
SELECT 1+(SELECT COUNT( distinct 平均成绩) FROM (SELECT S#,AVG(score) AS 平均成绩 FROM SC GROUP BY S# ) AS T1 WHERE 平均成绩 > T2.平均成绩) as 名次, S# as 学生学号,平均成绩 FROM (SELECT S#,AVG(score) 平均成绩 FROM SC GROUP BY S# ) AS T2 ORDER BY 平均成绩 desc;
SELECT t1.S# as 学生ID,t1.C# as 课程ID,Score as 分数 FROM SC t1 WHERE score IN (SELECT TOP 3 score FROM SC WHERE t1.C#= C# ORDER BY score DESC)
select c#, count(s#) from sc group by c#;
select sc.s#, student.sname, count(c#) as 选课数 from sc,student where sc.s# =student.s# group by sc.s#,Student.sname having count(c#)=1;
select count(Ssex) as 男生人数 from student group by Ssex having Ssex='男'; select count(Ssex) as 女生人数 from student group by Ssex having Ssex='女';
select sname from student where sname like '张%';
select sanme,count(*) from student group by sname havang count(*)>1;
select sname, convert(char(11),DATEPART(year,sage)) as age from student where convert(char(11),DATEPART(year,Sage))='1981';
select Sname,SC.S# ,avg(score) from Student,SC where Student.S#=SC.S# group by SC.S#,Sname having avg(score)>85;
select C#, avg(score) from sc group by c# order by avg(score), c# desc;
select sname, isnull(score,0) from student, sc ,course where sc.s#=student.s# and sc.c#=course.c# and course.cname='数据库' and score<60;
select sc.s#,sc.c#,sname,cname from sc,student course where sc.s#=student.s# and sc.c#=course.c#;
select distinct student.s#,student.sname,sc.c#,sc.score from student,sc where sc.score>=70 and sc.s#=student.s#;
select c# from sc where score<60 order by c#;
select sc.s#,student.sname from sc,student where sc.s#=student.s# and score>80 and c#='003';
select count(*) from sc;
select student.sname,score from student,sc,course c, teacher where student.s#=sc.S# and sc.c#=c.c# and c.T#=teacher.T# and teacher.tname='叶平' and sc.score=(select max(score) from sc where c#=c.c#);
select count(*) from sc group by c#;
select distinct a.s#,b.score from sc a ,sc b where a.score=b.score and a.c#<>b.c#;
select t1.s# as 学生ID,t1.c# 课程ID, Score as 分数 from sc t1 where score in (select top 2 score from sc where t1.c#=c# order by score desc) order by t1.c#;
select c# as 课程号,count(*) as 人数 from sc group by c# order by count(*) desc c#;
select s# from sc group by s# having count(*)>=2;
select c# ,cname from course where c# in (select c# from sc group by c#);
select sname from student where s# not in (select s# from course,teacher,sc where course.t#=teacher.t# and sc.c#=course.c# and tname='叶平');
select s#,avg(isnull(score,0)) from sc where s# in (select s# from sc where score<60 group by s# having count(*)>2) group by s#;
select s# from sc where c#='004' and score<60 order by score desc;
delect from sc where s#='002' and c#='001';
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
数据库SQL---数据库、基本表、视图、索引的定义、修改、删除
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (上)
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (下)
网友评论