查询各课程的平均成绩并按成绩降序排列
Selectcno,avg(grade)fromscgroupbycnoandorderbyavg(grade)desc为什么会出错...
Select cno,avg(grade) from sc group by cno and order by avg(grade) desc为什么会出错
展开
6个回答
展开全部
SQL指令:
SELECT stu.name,a4.java,a4.mysql,a4.html,a4.`总成绩` from
(select a.stu_id,a.score 'java',a1.score 'mysql',a2.score 'html',a3.sum1 '总成绩' from
(select sc.score,sc.stu_id from score sc where sc.subject_id=10001) a
LEFT JOIN
(select sc.score,sc.stu_id from score sc where sc.subject_id=10002) a1
on a.stu_id = a1.stu_id LEFT JOIN
(select sc.score,sc.stu_id from score sc where sc.subject_id=10003) a2
on a1.stu_id=a2.stu_id
LEFT JOIN (SELECT sum(sc.score) sum1 ,sc.stu_id from score sc GROUP BY sc.stu_id) a3
on a2.stu_id = a3.stu_id
ORDER BY a3.sum1 desc) a4
LEFT JOIN student stu on a4.stu_id = stu.id
SELECT stu.name,a4.java,a4.mysql,a4.html,a4.`总成绩` from
(select a.stu_id,a.score 'java',a1.score 'mysql',a2.score 'html',a3.sum1 '总成绩' from
(select sc.score,sc.stu_id from score sc where sc.subject_id=10001) a
LEFT JOIN
(select sc.score,sc.stu_id from score sc where sc.subject_id=10002) a1
on a.stu_id = a1.stu_id LEFT JOIN
(select sc.score,sc.stu_id from score sc where sc.subject_id=10003) a2
on a1.stu_id=a2.stu_id
LEFT JOIN (SELECT sum(sc.score) sum1 ,sc.stu_id from score sc GROUP BY sc.stu_id) a3
on a2.stu_id = a3.stu_id
ORDER BY a3.sum1 desc) a4
LEFT JOIN student stu on a4.stu_id = stu.id
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-10-17
展开全部
Select cno,avg(grade)
from sc
group by cno
order by avg(grade) desc
from sc
group by cno
order by avg(grade) desc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-10-17
展开全部
Select cno,avg(grade) avg_grade from sc group by cno and order by avg_grade desc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询