3、查询所有学生的学号、姓名、选课数、总成绩

-- 3、查询所有学生的学号、姓名、选课数、总成绩(不重要)
SELECT a.s_id,a.s_name,COUNT(b.c_id),SUM(b.s_score) 
FROM
student as a
LEFT JOIN  
score as b ON a.s_id=b.s_id
GROUP BY s_id,s_name
#方法二
SELECT b.s_id,b.s_name,COUNT(a.c_id),
-- 一般SELECT中出现的是group by中出现的或者是统计值

SUM(case WHEN a.s_score is NULL then 0 else a.s_score END)

FROM score as a
RIGHT JOIN student as b ON a.s_id=b.s_id
GROUP BY s_id,s_name

3、查询所有学生的学号、姓名、选课数、总成绩_第1张图片

你可能感兴趣的:(面试题)