日期:2014-05-17 浏览次数:20541 次
-->测试数据 if object_id('classInfo')is not null drop table classInfo go create table classInfo(cid int ,className varchar(20)) insert into classInfo values(1,'班级甲'); insert into classInfo values(2,'班级乙') if object_id('studentInfo')is not null drop table studentInfo go create table studentInfo(sid int ,stuName varchar(20)) insert into studentInfo values(1,'张三'); insert into studentInfo values(2,'李四'); insert into studentInfo values(2,'王五') if object_id('middleInfo')is not null drop table middleInfo go create table middleInfo(id int ,cid int ,sid int) insert into middleInfo values(1,1,1); insert into middleInfo values(2,1,2); insert into middleInfo values(3,1,3); insert into middleInfo values(4,2,1) -->测试查询 select c.className,d.stuName from ( select a.className,b.sid from classinfo a join middleinfo b on a.cid=b.cid )c join studentInfo d on d.sid=c.sid -->测试结果 ----------- -------------- /* className stuName 班级甲 张三 班级甲 李四 班级甲 王五 班级乙 张三 */
------解决方案--------------------