多对多 && 多对一 sql

* 1th
* 班级和学生的多对一
*
select * from t_stu s
LEFT JOIN t_clazz c on s.clazzid=c.clazzid Left JOIN t_college cc on s.collegeid=cc.collegeid*
* 2th
* 学生和体育爱好多对多
* select s.*, sp.sportname from t_stu s
LEFT JOIN t_stusport m on s.stuid=m.stuid LEFT JOIN t_sport sp on m.sportid=sp.sportid
*

* 3th
*
SELECT
s.*, c.clazzname,
cc.collegename,
GROUP_CONCAT(sp.sportname)
FROM
t_stu s
LEFT JOIN t_clazz c ON s.clazzid = c.clazzid
LEFT JOIN t_college cc ON s.collegeid = cc.collegeid
LEFT JOIN t_stusport m ON s.stuid = m.stuid
LEFT JOIN t_sport sp ON m.sportid = sp.sportid
GROUP BY
s.stuid

你可能感兴趣的:(sql)