34,872
社区成员
发帖
与我相关
我的任务
分享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
出来了?
--最后的疑惑是可用分真是少的可怜,谁赞助点吧
--这一句有疑惑
--按[^]的解释 理解为--字段中只要不含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
出来了?
疑惑在这,是不是这种写法是不合法的???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
*/