between 与 not between的问题

yaosmail 2009-04-24 09:28:50
请高手看看我下面两个语句:
语句1
select distinct a.str_deductbill_no
from [sellrebate].dbo.t_deduct_account_detail a

where a.str_bill_no between '200812260000' and '200903259999'

and str_deductbill_no='200901070089'
order by str_deductbill_no
////
语句2
select distinct a.str_deductbill_no
from [sellrebate].dbo.t_deduct_account_detail a

where a.str_bill_no not between '200812260000' and '200903259999'

and str_deductbill_no='200901070089'
order by str_deductbill_no
以上两个语句的区别是在between前一个有not一个没not
在本人看来一个两个语句查出的结果是相对的,可是恰恰相反。请问各位这是什么原因?

...全文
456 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaosmail 2009-04-30
  • 打赏
  • 举报
回复
问题已解决,是自己的疏忽,谢谢大家!
feifeiyiwen 2009-04-24
  • 打赏
  • 举报
回复
up
jimwoo 2009-04-24
  • 打赏
  • 举报
回复
select a.str_deductbill_no, a.str_bill_no
from [sellrebate].dbo.t_deduct_account_detail a
where str_deductbill_no='200901070089'

检查一下有几条记录
yaosmail 2009-04-24
  • 打赏
  • 举报
回复
如果语句改为
select distinct a.str_deductbill_no
from [sellrebate].dbo.t_deduct_account_detail a

where a.str_bill_no not between '200812260000' and '200903259999'

and str_deductbill_no='200901070089'

结果也一样
yaosmail 2009-04-24
  • 打赏
  • 举报
回复
加()没用的
再仔细说明一下,在[sellrebate].dbo.t_deduct_account_detail 表中有一个记录字段str_bill_no='200812250375'
他的 str_deductbill_no='200901070089'
大家看我的语句

select distinct a.str_deductbill_no
from [sellrebate].dbo.t_deduct_account_detail a

where a.str_bill_no between '200812260000' and '200903259999'

and str_deductbill_no='200901070089'
查询时应该不会出现str_deductbill_no='200901070089'
但是现在就是有这个记录出现,所以不知道原因?

谢谢大家回复!
jimwoo 2009-04-24
  • 打赏
  • 举报
回复
是不是只有一条记录'200901070089' ?

select distinct a.str_deductbill_no
from [sellrebate].dbo.t_deduct_account_detail a

where a.str_bill_no not between '200812260000' and '200903259999'

and str_deductbill_no='200901070089'
jimwoo 2009-04-24
  • 打赏
  • 举报
回复
这两个结果集应该是补集的关系,不知道LZ的恰恰相反具体是什么情况
conan304 2009-04-24
  • 打赏
  • 举报
回复
[Quote=引用楼主 yaosmail 的帖子:]
请高手看看我下面两个语句:
语句1
select distinct a.str_deductbill_no
from [sellrebate].dbo.t_deduct_account_detail a

where a.str_bill_no between '200812260000' and '200903259999'

and str_deductbill_no='200901070089'
order by str_deductbill_no
////
语句2
select distinct a.str_deductbill_no
from [sellrebate].dbo.t_deduct_account_detail a

where a.str_bill_no not betwe…
[/Quote]
用>和<不行么?
sdhdy 2009-04-24
  • 打赏
  • 举报
回复
加括号没用。
  • 打赏
  • 举报
回复
加()来修改运算的优先级
sdhdy 2009-04-24
  • 打赏
  • 举报
回复
不知道楼主的两个NO是什么关系?
ks_reny 2009-04-24
  • 打赏
  • 举报
回复
同意1樓的方法,或者
select distinct a.str_deductbill_no 
from [sellrebate].dbo.t_deduct_account_detail a
where str_deductbill_no='200901070089' and
a.str_bill_no not between '200812260000' and '200903259999'
order by str_deductbill_no
sdhdy 2009-04-24
  • 打赏
  • 举报
回复
不知道楼主的两个NO是什么关系?
ks_reny 2009-04-24
  • 打赏
  • 举报
回复
樓主你的意思是兩個語句查詢的結果是一樣?
rucypli 2009-04-24
  • 打赏
  • 举报
回复
不可能不相对 ,除非你的表在动态变动
htl258_Tony 2009-04-24
  • 打赏
  • 举报
回复
select distinct a.str_deductbill_no 
from [sellrebate].dbo.t_deduct_account_detail a
where (a.str_bill_no not between '200812260000' and '200903259999')
and str_deductbill_no='200901070089'
order by str_deductbill_no
后面这个加上括号试一下.

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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