已经有了学生表和分数表,两表有共同的列:id

查询所有学生的数学成绩,

但是我们不知道这些人是谁,那么就要查的更精准了
SELECT a.name, b.score
FROM student a, grade b
WHERE a.id = b.id
AND kemu = '数学'

成绩排序展示(倒序DESC)
SELECT a.name, b.score
FROM student a, grade b
WHERE a.id = b.id
AND kemu = '数学'
ORDER BY score
DESC

ASC升序展示了

sum求和:统计每个学生的总成绩,显示字段:姓名,总成绩
SELECT a.name,sum(b.score) as sum_score
from student a,grade b
where a.id=b.id
GROUP BY name

统计每个学生的总成绩(由于学生可能有重复名字),显示字段:学生 id,姓
名,总成绩
select a.id,a.name,c.sum_score
from student a,
(select b.id,sum(b.score)as sum_score
from grade b
group by id ) c
where a.id=c.id
order by sum_score
DESC

网友评论