select 语句中遇到的问题!谢谢!

sailor_Song 2002-11-26 10:00:08
use pubs
go
select au_id,au_lname,au_fname,state
from authors
where state='ca'
or state='ks'
or state='mi'
or state='in'
go
select au_id,au_lname,au_fname,state
from authors
where state in ('ca','ks','mi','IN')
go

select au_id,au_lname,au_fname,state
from authors
where state not in ('ca','ks','mi','IN')
go
这个pubs大家都知道,查询结果却令人费解:
第二个查询的结果中state='in'地点只有一个记录,
第三个查询的结果中state='in'地点也有一个记录,
并且两个记录是不同的,按查询条件:两个记录都是在第二个查询结果中,为什么各一个呢?
第一个查询和第二个查询结果是一样的!
回邮件:songxb@singlee.com.cn
谢谢!
...全文
40 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
愉快的登山者 2002-11-26
  • 打赏
  • 举报
回复
第三个查询:
au_id au_lname au_fname state
----------- ---------------------------------------- -------------------- -----
527-72-3246 Greene Morningstar TN
648-92-1872 Blotchet-Halls Reginald OR
807-91-6654 Panteley Sylvia MD
899-46-2035 Ringer Anne UT
998-72-3567 Ringer Albert UT

(5 row(s) affected)
没有错误。是TN,不是IN。
CrazyFor 2002-11-26
  • 打赏
  • 举报
回复

没有发现什么问题,你能说的再清楚点吗?
而且我看到的state='in'的,只有一条记录,不明白你说什么!
beata88 2002-11-26
  • 打赏
  • 举报
回复
你说的第一个查询和第二个查询结果一样没错。但在第三个查询结果中并没有state='in'的记录呀,只有一条state='TN'的记录,是不是你看错了呢?
sailor_Song 2002-11-26
  • 打赏
  • 举报
回复
tj_dns(愉快的登山者) 请您说清楚:什么是IN',什么是IN?
谢谢!
sailor_Song 2002-11-26
  • 打赏
  • 举报
回复
先用
select state
from authors
从中可以看出有两天记录state='in'的
然后用
select au_id,au_lname,au_fname,state
from authors
where state='in'
go
按理说应该有两条记录它们的state='in',但是只有一条记录是:
722-51-5454 DeFrance Michel IN
再用
select au_id,au_lname,au_fname,state
from authors
where state not in ('IN')
go
按理说state='in'的记录应该是被过滤掉的,但是其中有一条是:
527-72-3246 Greene Morningstar TN
这个是不是有点问题啊?

34,590

社区成员

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

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