如何得到join之外的值
有10张表做Join得出结果集为W,现在根据getdate()需要再去表vacation中查找,如果存在而且在beginTime, EndTime之间,则排除此用户
create table vacation (id int, uidd int,beginTime, EndTime)
insert into vacation values( 1, 1, 2012-03-29 10:00:00.000,2012-03-29, 20:00:00.000)
create table w ( uidd int, score int)
insert into w values( 1, 20)
insert into w values( 2, 20)
insert into w values( 3, 20)
结果:因为vacation 表uidd有1,如果getdate() 在2012-03-29 10:00:00.000,2012-03-29, 20:00:00.000 之间,则显示
2,20
3,20
否则显示
1,20
2,20
3,20
如何写sql?为什么full join不行啊?另外,这10个表join的性能已经有点慢,期望高效写法,sql2k5,谢谢!
[解决办法]
create table vacation (id int, uidd int,beginTime datetime, EndTime datetime)insert into vacation values( 1, 1, '2012-03-29 10:00:00.000','2012-03-29 20:00:00.000')create table w ( uidd int, score int)insert into w values( 1, 20)insert into w values( 2, 20)insert into w values( 3, 20)select w.* from w where not exists(select 1 from vacation v where v.uidd = w.uidd and getdate() between v.beginTime and v.EndTime)drop table vacation , w/*uidd score ----------- ----------- 1 202 203 20(所影响的行数为 3 行)*/