请高手帮我写个查询语句
我的表结构
id test
1 1
2 2
3 4
4 6
5 8
6 9
7 10
8 11
9 12
怎么才能查询出 3 5 7这三个数字。
就是不在1-12 中的数据
我的表结构
id test
1 1
2 2
3 4
4 6
5 8
6 9
7 10
8 11
9 12
怎么才能查询出 3 5 7这三个数字。
就是不在1-12 中的数据
解决方案 »
- 数据库路径错误提问?
- 兄弟们是否知道WebBrowser已经显示好的页面转换成图片的方法,我阅读网络杂志想复制下来几页以后看。
- ?急! ClientSocket能通过代理服务器连接互联网上的ServerSocket吗? 具体如何做???
- 三层的问题请教
- forgot的散分帖:这里有上海华东理工大学的朋友吗?请进来说两句(上海的朋友也可以)。
- 請問如何判斷TList對象中每一個對象的數据類型?
- 怎样在字符串中取出数字?
- delphi2005使用MainMenu控件的问题
- delphi 时间间隔问题
- ontimer和其他事件是不是并行的?
- 关于流的几个小问题,请各位老大帮帮忙啊!
- delphi之家欢迎大家的加入.共同交流技术..13771002
where not (id in(select distinct test from tbl_test ))
----------------
废话!你查的不就是ID字段么?
declare @T Table (id varchar(10),test varchar(10))
--插入数据
insert into @t
select '1','1' union
select '2','2' union
select '3','4' union
select '4','6' union
select '5','8' union
select '6','9' union
select '7','10' union
select '8','11' union
select '9','12'
--select test from @t
declare @intMaxID int,@i int
declare @intIdentity table (Rid int)
select @intMaxID=max(convert(int,test)) from @t
set @i=1
while @i<@intMaxID
begin
insert into @intIdentity
select @i
set @i=@i+1
end
--select * from @intIdentityselect Rid from @intIdentity where Rid not in (select test from @T)
------------结果
declare @T Table (id varchar(10),test varchar(10))
--插入数据
insert into @t
select '1','1' union
select '2','2' union
select '3','4' union
select '4','6' union
select '5','8' union
select '6','9' union
select '7','10' union
select '8','11' union
select '9','12'
--select test from @t
declare @intMaxID int,@i int
declare @intIdentity table (Rid int)
select @intMaxID=max(convert(int,test)) from @t
set @i=1
while @i<@intMaxID
begin
insert into @intIdentity
select @i
set @i=@i+1
end
--select * from @intIdentityselect Rid from @intIdentity where Rid not in (select test from @T)
------------------结果
Rid
-----------
3
5
7
set nocount on
declare @T Table (id varchar(10),test varchar(10))
--插入数据
insert into @t
select '1','1' union
select '2','2' union
select '3','4' union
select '4','6' union
select '5','8' union
select '6','9' union
select '7','10' union
select '8','11' union
select '9','12'
--select test from @t
declare @intMaxID int,@i int
declare @intIdentity table (Rid int)
select @intMaxID=max(convert(int,test)) from @t
set @i=1
while @i<@intMaxID
begin
insert into @intIdentity
select @i
set @i=@i+1
end
--select * from @intIdentityselect Rid from @intIdentity where Rid not in (select test from @T)------------------结果
Rid
-----------
3
5
7
不过只要你出现的最大值后面的记录没有,不管你有多少次,这点计算使用表变量是很快的.
select id from atable where id not in (select test from atable);
结果为
3
5
7