积极答复者
SQL server 中not like和对查询值进行^处理的查询方法有什么区别?

问题
-
--如下:
create database cx
use cx
create table xx
(a int not null primary key,aa text)
select *from xx
insert into xx values (1,'asd1234567890A')
insert into xx values (2,'asd112890A')
insert into xx values (3,'asd2890A')
select*from xx where aa like 'asd[1]%' --1
select*from xx where aa not like 'asd[1]%' --2
select*from xx where aa like 'asd[^1]%' --3
select*from xx where aa not like 'asd[^1]%' --4虽然有些查询结果是相同的,但是问题来了:
第一条查询和第四条有什么区别?
第二条和第三条有什么区别?
答案
-
From boos online:
[ ]
Any single character within the specified range ([a-f]) or set ([abcdef]).
WHERE au_lname LIKE '[C-P]arsen' finds author last names ending with arsen and starting with any single character between C and P, for example Carsen, Larsen, Karsen, and so on. In range searches, the characters included in the range may vary depending on the sorting rules of the collation.
[^]
Any single character not within the specified range ([^a-f]) or set ([^abcdef]).
WHERE au_lname LIKE 'de[^l]%' all author last names starting with de and where the following letter is not l.
- 已建议为答案 Herro wongMicrosoft contingent staff, Moderator 2016年5月17日 5:49
- 已标记为答案 Herro wongMicrosoft contingent staff, Moderator 2016年5月30日 5:49
-
你再插入一条不是asd开头的,就发现区别了。
如果没有前面的,like[1]和not like [^1]倒确实没啥区别。
想不想时已是想,不如不想都不想。
- 已建议为答案 Herro wongMicrosoft contingent staff, Moderator 2016年5月17日 5:49
- 已标记为答案 Herro wongMicrosoft contingent staff, Moderator 2016年5月30日 5:49
全部回复
-
From boos online:
[ ]
Any single character within the specified range ([a-f]) or set ([abcdef]).
WHERE au_lname LIKE '[C-P]arsen' finds author last names ending with arsen and starting with any single character between C and P, for example Carsen, Larsen, Karsen, and so on. In range searches, the characters included in the range may vary depending on the sorting rules of the collation.
[^]
Any single character not within the specified range ([^a-f]) or set ([^abcdef]).
WHERE au_lname LIKE 'de[^l]%' all author last names starting with de and where the following letter is not l.
- 已建议为答案 Herro wongMicrosoft contingent staff, Moderator 2016年5月17日 5:49
- 已标记为答案 Herro wongMicrosoft contingent staff, Moderator 2016年5月30日 5:49
-
你再插入一条不是asd开头的,就发现区别了。
如果没有前面的,like[1]和not like [^1]倒确实没啥区别。
想不想时已是想,不如不想都不想。
- 已建议为答案 Herro wongMicrosoft contingent staff, Moderator 2016年5月17日 5:49
- 已标记为答案 Herro wongMicrosoft contingent staff, Moderator 2016年5月30日 5:49