1、建立主表(user)和子表(score)
2、user表数据
3、score表数据
4、查出user基本数据以及每个学生的考试总分数
错误实例:
select u.*,sum(s.score) from user u inner join score s
on u.user_id = s.user_id;
正确实例:
select u.*,sum(s.score) from user u inner join score s
on u.user_id = s.user_id
group by u.user_id
加分组:
select u.*,sum(s.score) from user u inner join score s
on u.user_id = s.user_id
where u.user_id = 4
group by u.user_id
不加分组: