求一个查询问题

zblaoshu1979 2006-09-08 05:02:07
有两个表
a(基本信息表)
id name type value
1 a 1 100
2 b 1 209
3 c 2 333
4 d 3 123


b(value_b和value_e是一个值的范围)
type value_b value_e
1 1 150
1 210 300
2 100 200
3 100 200
用type关联,我想求出a表的值不在b表的值范围内的,b表中的type有重复的,只要在一个的范围内就行,就是说比如第一个1,a,1,100,是在1,150的范围内,就不用取他了,只要在一个范围内就行
得出数据
id name type value
2 b 1 209
...全文
221 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hyh801222 2006-09-08
  • 打赏
  • 举报
回复
顶一个吧
Well 2006-09-08
  • 打赏
  • 举报
回复
楼主!!
zsforever 2006-09-08
  • 打赏
  • 举报
回复
zicxc(冒牌邹建 V0.3) 的可以了
子陌红尘 2006-09-08
  • 打赏
  • 举报
回复
select
*
from
a
where
not exists(select 1 from b where type=a.type and a.value between value_b and value_e)
zicxc 2006-09-08
  • 打赏
  • 举报
回复
一楼所有数据都出来了
zicxc 2006-09-08
  • 打赏
  • 举报
回复
select * from a a1
where not exists (
select 1 from b where type=a1.type
and a1.value between b.value_b and b.value_e
)

xyxfly 2006-09-08
  • 打赏
  • 举报
回复
up 一个,先下班了
^_^
iamltd 2006-09-08
  • 打赏
  • 举报
回复
select distinct a.* from a inner join b on a.type=b.type and a.value not between b.value_b and b.value_e

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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