日期:2014-05-19  浏览次数:20425 次

求一条不难的SQL语句.
有表
S   (SNO,SNAME)   学生关系。SNO   为学号,SNAME   为姓名
C   (CNO,CNAME,CTEACHER)   课程关系。CNO   为课程号,CNAME   为课程名,CTEACHER   为任课教师
SC(SNO,CNO,SCGRADE)   选课关系。SCGRADE   为成绩  

列出有二门以上(含两门)不及格(不及格为60以下)课程的学生姓名及其平均成绩  


SQL   查询要怎么写,   谢谢解答@

------解决方案--------------------
表打击人啊. 你们又不给答案就打击. BS

这个题目,我没做上..汗... 我考我同事,他作上了.

select s.sno , s.sname , t.scgrade from s,
(
select sno , avg(scgrade) as scgrade from scgrade < =60 group by sno having count(*) > = 2
) t
where s.sno = t.sno
------解决方案--------------------
select s.sno , s.sname , t.scgrade from s,
(
select sno , avg(scgrade) as scgrade from SC where sc.scgrade < =60 group by sno having count(*) > = 2
) t
where s.sno = t.sno

------解决方案--------------------
练习了一把,楼上用having很好啊,我都忘记了
SELECT a.sno, sname, a.avggrade
FROM [SELECT sno, count(sno) AS num, avg(scgrade) as avggrade
FROM sc
WHERE (scgrade <60)
GROUP BY sno]as a, s
WHERE (a.num > =2) and (a.sno = s.sno)