现在有这样一张表,只是打个比喻(下面两个表都是同一个表,左边是星期一的数据,右边是星期二的数据,现在要做的就是找出星期二增加的数据,就是一行中a,b,c这三列只要有一个与前一天的不一样,就是增加的数据)(再说明下星期二的表有增加的数据,也有删除的数据,所以通过ID查询是不行的)
a b c d a b c d
1 2 3 日期 1 2 3 日期
1 5 8 日期 2 3 3 日期
2 3 3 日期 1 2 5 日期
5 3 4 日期 5 2 4 日期现在需要查询出 a b c d
1 2 5 日期
5 2 4 日期这样的SQL语句怎么写 想了半天没有搞定。好像以前看到过这样的问题现在忘记了。
a b c d a b c d
1 2 3 日期 1 2 3 日期
1 5 8 日期 2 3 3 日期
2 3 3 日期 1 2 5 日期
5 3 4 日期 5 2 4 日期现在需要查询出 a b c d
1 2 5 日期
5 2 4 日期这样的SQL语句怎么写 想了半天没有搞定。好像以前看到过这样的问题现在忘记了。
from t2
where exists (select 1 from t1 where t1.a=t2.a and t1.b=t2.b and t1.c=t2.c)
select *
from t2
where not exists (select 1 from t1 where t1.a=t2.a and t1.b=t2.b and t1.c=t2.c)
left join tb b
on a.a=b.a and a.b=b.b and a.c=b.c and b.日期='星期一'
where a.日期='星期二' and b.a is null
from tb a left join tb b
on a.a=b.a and a.b=b.b and a.c=b.c and b.日期='星期一'
where a.日期='星期二' and b.a is null
insert into #a select 1, 2,3 ,'2008-11-17'
insert into #a select 1, 5,8 ,'2008-11-17'
insert into #a select 2, 3,3 ,'2008-11-17'
insert into #a select 5, 3 ,4 ,'2008-11-17'
insert into #a select 1, 2 ,3 ,'2008-11-18'
insert into #a select 2, 3 ,3 ,'2008-11-18'
insert into #a select 1, 2 ,5 ,'2008-11-18'
insert into #a select 5, 2 ,4 ,'2008-11-18' select * from #a where s_date='2008-11-18'
and code1+code2+code3 not in (select code1+code2+code3 from #a where s_date='2008-11-17' )drop table #a/**
code1 code2 code3 s_date
---------- ---------- ---------- ----------
1 2 5 2008-11-18
5 2 4 2008-11-18(2개 행 적용됨)
1 21 1
12 1 1
1 2 11
...对于数字型+
1 2 3
3 2 1
0 1 5
...这样的数据是分不清的。