a b c 1 1 2 1 2 3 2 1 3 2 2 4 3 1 2 3 4 2 4 5 2 4 6 3 5 1 3 5 4 3 5 5 2这样的表,我想通过2个变量,来取从第x条开始,取y条记录 如果有一列是唯一的,就好办了,直接如下实现: select top y * from A where id not in (select top x id from A) 但现在是两列联合起来做唯一键, select top y * from A where (a,b) not in (select top x a,b from A) 这样的条件如何实现呢?
Select top 10 * from A x left join (select top 10 a from A) y on x.a = y.a left join (select top 10 b from A) z on x.b = z.b where y.a is null and z.b is null 写sql的时候可以不用到not in尽量不要用,not in效率太不好了
Select top 10 * from A where a not in(select top 10 a from A) and b left join (select top 10 b from A)
where '@#$@'+a+b+'@#$@' not in(select top 10 '@#$@'+a+b+'@#$@' from A)
Select top 10 * from A left join (select top 10 a,b from A) b on a.a=b.a and a.b=b.b where b.a is null and b.b is null
where not exists(select top 10 a,b from A as A2 where A1.a=A2.a and A1.b=A2.b)试试。手写的,没开SQL试过,不对请见谅
from A
where a not in(select top 10 a from A) and b not in(select top 10 b from A)
可以改成用left join
1 1 2
1 2 3
2 1 3
2 2 4
3 1 2
3 4 2
4 5 2
4 6 3
5 1 3
5 4 3
5 5 2这样的表,我想通过2个变量,来取从第x条开始,取y条记录
如果有一列是唯一的,就好办了,直接如下实现:
select top y * from A where id not in (select top x id from A)
但现在是两列联合起来做唯一键,
select top y * from A where (a,b) not in (select top x a,b from A)
这样的条件如何实现呢?
Select top 10 * from A x
left join (select top 10 a from A) y on x.a = y.a
left join (select top 10 b from A) z on x.b = z.b
where y.a is null and z.b is null
写sql的时候可以不用到not in尽量不要用,not in效率太不好了
from A
where a not in(select top 10 a from A) and b left join (select top 10 b from A)
from A left join (select top 10 a,b from A) b on a.a=b.a and a.b=b.b where b.a is null and b.b is null