当前位置: 代码迷 >> Sql Server >> SQL Server题目,这应该如何做,帮帮忙多谢大家
  详细解决方案

SQL Server题目,这应该如何做,帮帮忙多谢大家

热度:99   发布时间:2016-04-24 09:35:38.0
SQL Server题目,这应该怎么做,帮帮忙谢谢大家!

------解决思路----------------------
1)

select S# from SC as a where C#='001' and  exists (select 1 from SC where S#=a.S# and C#='002' and score<a.score) 

2)

select S#,avg(score) as 平均成绩 from SC group by S# having avg(score)>60

3)

delete a from SC as a,Course as b,Teacher as c where a.C#=b.C# and b.T#=c.T# and c.Tname='叶平'

4)

select C# as 课程ID,max(score) as 最高分,min(score) as 最低分 from SC group by C#

------解决思路----------------------
引用:
1)

select S# from SC as a where C#='001' and  exists (select 1 from SC where S#=a.S# and C#='002' and score<a.score) 

2)

select S#,avg(score) as 平均成绩 from SC group by S# having avg(score)>60

3)

delete a from SC as a,Course as b,Teacher as c where a.C#=b.C# and b.T#=c.T# and c.Tname='叶平'

4)

select C# as 课程ID,max(score) as 最高分,min(score) as 最低分 from SC group by C#

弄错顺序了
1)

select S# from SC as a where C#='001' and  exists (select 1 from SC where S#=a.S# and C#='002' and score<a.score) 

2)

select S#,avg(score) as 平均成绩 from SC group by S# having avg(score)>60

3)

update a set score=e.score from SC as a,(select C#,avg(score) as score from SC as b,Course as c,Teacher as d where b.C#=c.C# and c.T#=d.T# and d.Tname='叶平' group by b.C# ) as e where a.C#=e.C#

4)

delete a from SC as a,Course as b,Teacher as c where a.C#=b.C# and b.T#=c.T# and c.Tname='叶平'

5)

select C# as 课程ID,max(score) as 最高分,min(score) as 最低分 from SC group by C#

------解决思路----------------------
SQL基础,用到些基础函数,子查询,分组等,LZ好好练习下,打好基本功这些都不难滴!
------解决思路----------------------
没数据也没调试,不知道对不对,LZ自己调试吧
CREATE TABLE #STUDENT(S# VARCHAR(20),SNAME VARCHAR(20), SAGE VARCHAR(20),SSEX VARCHAR(20))
CREATE TABLE #COURSE(C# VARCHAR(20),CNAME VARCHAR(20),T# VARCHAR(20))
CREATE TABLE #SC(S# VARCHAR(20),C# VARCHAR(20),SCORE INT)
CREATE TABLE #TEACHER(T# VARCHAR(20),TNAME VARCHAR(20))

1.SELECT A.S#,MAX(SCORE) '最大成绩'
FROM #STUDENT  A
LEFT JOIN #SC  B
ON A.S#=B.S#
LEFT JOIN #COURSE  C
ON B.C#=C.C#
WHERE SCORE>(
SELECT SCORE 
FROM #COURSE F 
JOIN #SC G ON  F.C#=G.C#
WHERE CNAME='001'
)
AND CNAME='002'
GROUP BY A.S#

2.SELECT A.S#,AVG(SCORE) 
FROM #SC A 
JOIN #STUDENT B ON A.S#=B.S# 
GROUP BY A.S# 
HAVING AVG(SCORE)>60
ORDER BY A.S#

3.UPDATE #SC
SET SCORE=
(SELECT AVG(SCORE) 
FROM #SC 
GROUP BY C#
)
WHERE C# IN
(SELECT C.C#
FROM #TEACHER A 
LEFT JOIN #COURSE B ON A.T#=B.T#
LEFT JOIN #SC C ON B.C#=C.C#
LEFT JOIN #STUDENT D ON C.S#=D.S#
WHERE A.TNAME='叶平'
)

4.DELETE #SC
WHERE  S# = (SELECT C.S#
FROM #TEACHER A 
LEFT JOIN #COURSE B ON A.T#=B.T#
LEFT JOIN #SC C ON B.C#=C.C#
LEFT JOIN #STUDENT D ON C.S#=D.S#
WHERE A.TNAME='叶平'
)



------解决思路----------------------
http://blog.csdn.net/fredrickhu/article/details/4592668
  相关解决方案