简单来说:前半段是【学过‘001’课程的学生】,后半段是【学过‘002’课程的学生】;其中【 where SC_2.S#=SC.S# 】是把前后两段结果连接起来的关键,相当于把两个结果 Inner Join,从而得出最终结果【同时学过‘001’和‘002’的学生】。先查SC表获取SID和对应所选课程按一定顺序排序的CID字符串的拼接...
6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名:SELECT st.SId,st.StuName FROM(SELECT t1.SId AS SId FROM (SELECT s1.SId FROM sc s1 WHERE s1.CId = '001')t1,(SELECT s2.SId FROM sc s2 WHERE s2.CId = '002')t2 WHERE t1.SId = t2.SId )stu, student st WHERE stu...
号“002”课程的同学的学号、姓名 查询学过“001”并且也学过编号“002”课程的同学的学号、姓名:我的写法:第⼀步:先查出来学过“001”并且也学过编号“002”课程的同学的学号:SELECT t11.t1sid t33id FROM (SELECT t1.StuId t1sid FROM tblscore t1 WHERE t1.CourseId='001')t11,-- 001的学⽣...
6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名: SELECTst.SId, st.StuNameFROM(SELECTt1.SIdASSIdFROM(SELECTs1.SIdFROMsc s1WHEREs1.CId='001')t1, (SELECTs2.SIdFROMsc s2WHEREs2.CId='002')t2WHEREt1.SId=t2.SId )stu, student stWHEREstu.SId=st.SId 在MySQL命令行中的运行...
6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名: SELECTst.SId, st.StuNameFROM(SELECTt1.SIdASSIdFROM(SELECTs1.SIdFROMsc s1WHEREs1.CId='001')t1, (SELECTs2.SIdFROMsc s2WHEREs2.CId='002')t2WHEREt1.SId=t2.SId )stu, student stWHEREstu.SId=st.SId ...