请教sql语句:我们要计算一个表的一个列的值不在0-1000之间的记录显示出来,在线等待,解决了马上给分100

iec 2006-04-23 08:30:27
例如:
我用access数据库.
表A
data
1
2
3
4
6
9
11
要求结果为:
5
7
8
10
怎样写效率高些?
...全文
348 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
itblog 2006-04-25
  • 打赏
  • 举报
回复
select data-1 as 缺号 from 表A a where data>1 and not exists(select 1 from 表A where data=a.data-1)
jixiaojie 2006-04-24
  • 打赏
  • 举报
回复
select id from 辅助查询表 a left join 标准表 b
on a.id=b.id
where b.id is null
order by a.id
NaSao 2006-04-24
  • 打赏
  • 举报
回复
select * from table where data<0 and data>1000

以上是不是就能满足楼主的要求?选出data值不在0到1000之间的记录.
iec 2006-04-24
  • 打赏
  • 举报
回复
错了,就是说找出表中的在0_1000中缺了的数,看题目
iec 2006-04-24
  • 打赏
  • 举报
回复
jwt1982(飞星) 说的对,但是查询速度很慢,我建了一个辅助表.
iec 2006-04-24
  • 打赏
  • 举报
回复
我的意思是A表中的字段值不在0-1000的数找出来,不是NaSao(nasao)那个意思.
jwt1982 2006-04-24
  • 打赏
  • 举报
回复
不建立临时表,那就干脆建立一个查询辅助表就是了

里边是 1-1000,或者其他都可以

select id from 辅助查询表 where id not in (select ID from 标准表)
hyrongg 2006-04-23
  • 打赏
  • 举报
回复
我们要计算一个表的一个列的值不在0-1000之间的记录显示出来,

这样的效率会很低吗?
select data from table where data<=0
union all
select data from table where data>=1000

求解
iec 2006-04-23
  • 打赏
  • 举报
回复
access数据库应该怎样做呢?不能建临时表的.
ReViSion 2006-04-23
  • 打赏
  • 举报
回复
不在序号表则列出
ReViSion 2006-04-23
  • 打赏
  • 举报
回复
最简单的办法,也可能是效率最高的方法

建一个序号表,
然后去对应
OracleRoob 2006-04-23
  • 打赏
  • 举报
回复

--在SQL Server中可以按如下处理

create table #A(data int)
go

insert into #A(data)
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 6 union all
select 9 union all
select 11


--生成临时表,保存1,2,....,999,1000这1000个数字
select top 1000 identity(int,1,1) as id
into #tp
from syscolumns c1 inner join syscolumns c2 on 1=1


select * from #A
--select * from #tp


--查出所有#A中最小Data和最大Data之间不连续的数字
select id as data from #tp where id not in (select data from #A) and id<=(select max(data) from #A)


drop table #A,#tp

iec 2006-04-23
  • 打赏
  • 举报
回复
up

27,581

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧