日期:2014-05-18 浏览次数:20404 次
SELECT C_Score,S_Name,S_ID,E_Title FROM Scores,Teachers,Students,Essay WHERE T_ID='1' and Teachers.T_Group=Students.S_Group and Students.S_ID=Essay.E_SID not Exists {SELECT * FROM Scores,Teachers,Students WHERE Scores.C_TID=Teachers.T_ID and Scores.C_SID=Students.S_ID)
--这种语法上就应该没有问题了,但是估计你也很难得到你想要的结果。 SELECT C_Score,S_Name,S_ID,E_Title FROM Scores,Teachers,Students,Essay WHERE T_ID='1' and Teachers.T_Group=Students.S_Group and Students.S_ID=Essay.E_SID and not Exists --少个and ( --之前括号确实不对 SELECT * FROM Scores,Teachers,Students,Essay WHERE --这个位置少个表 Scores.C_TID=Teachers.T_ID and Scores.C_SID=Students.S_ID )
------解决方案--------------------
--> 测试数据: @a declare @a table (id int) insert into @a select 1 union all select 2 union all select 3 --> 测试数据: @b declare @b table (col int) insert into @b select 2 union all select 3 union all select 4 --> 测试数据: @c declare @c table (c int) insert into @c select 4 union all select 5 union all select 6 --> 测试数据: @d declare @d table (d int) insert into @d select 3 union all select 4 union all select 5 --四个表内连接,很容易没有结果的 select * from @a a,@b b,@c c,@d d where not exists (select * from @a a,@b b,@c c,@d d where b.col=c.c)
------解决方案--------------------
你把exists理解成in了
按照你的意思用except就应该可以了。