场景
在查询学生信息中,允许学生宿舍信息为空,如果有获取,没有为空
select t.*, cs_sc_studenthostel.name as hostelname
from (
select cs_sc_student.id as student_id,
cs_sc_student.name as studentname,
cs_sc_class.name as classname,
cs_sc_student.sc_studenthostel_id
from cs_sc_student, cs_sc_class
where cs_sc_student.sc_class_id = cs_sc_class.id) t
left join cs_sc_studenthostel on t.sc_studenthostel_id = cs_sc_studenthostel.id
第一步 获取到学生的基础信息
(
select cs_sc_student.id as student_id,
cs_sc_student.name as studentname,
cs_sc_class.name as classname,
cs_sc_student.sc_studenthostel_id
from cs_sc_student, cs_sc_class
where cs_sc_student.sc_class_id = cs_sc_class.id) t
第二步 进行左连接
left join cs_sc_studenthostel on t.sc_studenthostel_id = cs_sc_studenthostel.id
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。