SQL最近僧多粥少,提问一下活跃气氛--LIKE [^]的疑惑

黄_瓜 2009-08-09 09:22:14
If not object_id('[student_info]') is null
Drop table [student_info]
Go
Create table [student_info]([student_id] int)
Insert student_info
Select 0 union all
Select 1 union all
Select 2 union all
Select 3 union all
Select 4 union all
Select 5 union all
Select 6 union all
Select 7 union all
Select 8 union all
Select 9 union all
Select 10 union all
Select 11 union all
Select 12 union all
Select 13 union all
Select 14 union all
Select 15 union all
Select 16 union all
Select 17 union all
Select 18 union all
Select 19 union all
Select 20 union all
Select 21 union all
Select 213 union all
Select 218 union all
Select 123456 union all
Select 7123456 union all
Select 71234568 union all
Select 22
Go
--这个没有遗憾
select * from student_info where [student_id] like '[^1-6]%
/*
student_id
-----------
0
7
8
9
7123456
71234568

(6 行受影响)

*/
--这个也没有疑惑

select * from student_info where [student_id] like '%[1-6]%'--字段中只要不含1至6的字符就显示出来
--数据多,就不贴出来了
--疑惑在这
student_id
-----------
0
7
8
9
10
17
18
19
20
218
7123456
71234568

(12 行受影响)

--是在看不懂
为什么
10
17
18
19
20
218
7123456
71234568
出来了?
--最后的疑惑是可用分真是少的可怜,谁赞助点吧
...全文
141 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
claro 2009-08-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 happyflystone 的回复:]
这不要解释了吧
[/Quote]
SQL77 2009-08-09
  • 打赏
  • 举报
回复
呵呵,这个东西不是有一个人问过
水族杰纶 2009-08-09
  • 打赏
  • 举报
回复
UP
百年树人 2009-08-09
  • 打赏
  • 举报
回复
...
feixianxxx 2009-08-09
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 beirut 的回复:]
引用 12 楼 htl258 的回复:
引用 8 楼 beirut 的回复:
SQL code--这一句有疑惑
--按[^]的解释 理解为--字段中只要不含1至6的字符就显示出来select*from student_infowhere[student_id]like'%[^1-6]%'/*student_id
-----------
0
7
8
9
10
17
18
19
20
218
7123456
71234568

(12 行受影响)*/¡­

--其中只要有一个字符不含1-6就显示出来。你盘点一下是不是?

明白了,应该理解为只要有一个字符不含1-6就显示出来
呵呵集合的东西都忘完了,有必要在回头看看,对编程来说数学是那么的重要
[/Quote]
看来我解释错了
黄_瓜 2009-08-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 happyflystone 的回复:]
这不要解释了吧
[/Quote]
我啥时候能达到石头哥你的水平,就没有什么东西需要别人解释了
黄_瓜 2009-08-09
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 htl258 的回复:]
引用 8 楼 beirut 的回复:
SQL code--这一句有疑惑
--按[^]的解释 理解为--字段中只要不含1至6的字符就显示出来select*from student_infowhere[student_id]like'%[^1-6]%'/*student_id
-----------
0
7
8
9
10
17
18
19
20
218
7123456
71234568

(12 行受影响)*/¡­

--其中只要有一个字符不含1-6就显示出来。你盘点一下是不是?
[/Quote]
明白了,应该理解为只要有一个字符不含1-6就显示出来
呵呵集合的东西都忘完了,有必要在回头看看,对编程来说数学是那么的重要
htl258_Tony 2009-08-09
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 beirut 的回复:]
SQL code--这一句有疑惑
--按[^]的解释 理解为--字段中只要不含1至6的字符就显示出来select*from student_infowhere[student_id]like'%[^1-6]%'/*student_id
-----------
0
7
8
9
10
17
18
19
20
218
7123456
71234568

(12 行受影响)*/¡­
[/Quote]
--其中只要有一个字符不含1-6就显示出来。你盘点一下是不是?
黄_瓜 2009-08-09
  • 打赏
  • 举报
回复
select * from student_info where [student_id] like '%[^1-6]%'--因为你最前面有个% 说明是 第二位不含哟1-6就显示

按你说的
218
7123456
71234568

为什么出来?
华夏小卒 2009-08-09
  • 打赏
  • 举报
回复
黄_瓜 2009-08-09
  • 打赏
  • 举报
回复
select * from student_info where [student_id] like '%[^1-6]%'

这句不懂
黄_瓜 2009-08-09
  • 打赏
  • 举报
回复
--这一句有疑惑 
--按[^]的解释 理解为--字段中只要不含1至6的字符就显示出来

select * from student_info where [student_id] like '%[^1-6]%'
/*student_id
-----------
0
7
8
9
10
17
18
19
20
218
7123456
71234568

(12 行受影响)
*/
为什么10
17
18
19
20
218
7123456
71234568
出来了?
疑惑在这,是不是这种写法是不合法的???
feixianxxx 2009-08-09
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 beirut 的回复:]
贴错了,我要修改,没修改了
[/Quote]

你哪句不懂
黄_瓜 2009-08-09
  • 打赏
  • 举报
回复
贴错了,我要修改,没修改了
feixianxxx 2009-08-09
  • 打赏
  • 举报
回复
If not object_id('[student_info]') is null
Drop table [student_info]
Go
Create table [student_info]([student_id] int)
Insert student_info
Select 0 union all
Select 1 union all
Select 2 union all
Select 3 union all
Select 4 union all
Select 5 union all
Select 6 union all
Select 7 union all
Select 8 union all
Select 9 union all
Select 10 union all
Select 11 union all
Select 12 union all
Select 13 union all
Select 14 union all
Select 15 union all
Select 16 union all
Select 17 union all
Select 18 union all
Select 19 union all
Select 20 union all
Select 21 union all
Select 22
Go


select * from student_info where [student_id] like '%[1-6]%'--有1-6 就显示
select * from student_info where not [student_id] like '%[1-6]%'--不含1-6 任意一个
select * from student_info where [student_id] like '%[^1-6]%'--因为你最前面有个% 说明是 第二位不含哟1-6就显示
--你改成这样
select * from student_info where [student_id] like '[^1-6]%'
/*
student_id
-----------
0
7
8
9

*/
-狙击手- 2009-08-09
  • 打赏
  • 举报
回复
这不要解释了吧
liangCK 2009-08-09
  • 打赏
  • 举报
回复
sf
htl258_Tony 2009-08-09
  • 打赏
  • 举报
回复
到底哪句有疑惑?
--小F-- 2009-08-09
  • 打赏
  • 举报
回复
SF

34,872

社区成员

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

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