为什么[^ ali]不能像 [英] Why [^ali] not work by like

查看:81
本文介绍了为什么[^ ali]不能像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1-我有桌子:



 id姓名

1阿里

2 Reza

3 Omid





2-我想给出不相等的名字'阿里有类似的操作:



 选择 * 来自 Tbl 其中名称喜欢 [^ Ali] 





我的尝试:



为什么[ ^ Ali]无法使用Like query

解决方案

如果你想过滤不像Ali的名字,你可以根据你的尝试尝试下列之一要求 -

  SELECT  *  FROM  Tbl  WHERE 名称  LIKE  ' %Ali%'   -   不包含Ali  
SELECT * FROM Tbl WHERE 名称 NOT LIKE ' %Ali' - 不以阿里结尾
SELECT * FROM Tbl < span class =code-keyword> WHERE 名称 NOT LIKE ' Ali%' - 不是从Ali开始
SELECT * FROM Tbl WHERE 名称<> ' Ali' - 不等于Ali
SELECT * FROM Tbl WHERE 名称 NOT LIKE ' Ali' - 与上述相同





如果您的要求不是其他,请告诉我。



谢谢


您的查询不起作用有两个原因。


首先 [^ Ali] 是一个字符串而不是一列,所以它需要被单引号包围'[^ Ali]'



其次你所包含的是必须匹配的字符集,你没有包含任何可以匹敌的东西。所以请尝试这样做

 选择 * 来自 Tbl 其中名称喜欢 ' %[^阿里]%' 


1- I have table with:

id      Name

1       Ali

2       Reza

3       Omid



2- I want to give name that not equal 'Ali' with like operation :

select * from Tbl where Name like [^Ali]



What I have tried:

why [^Ali] not work by Like query

解决方案

If you want to filter names which are not like "Ali", you could have tried one of the following based upon your requirement-

SELECT * FROM Tbl WHERE Name NOT LIKE '%Ali%' --not contains Ali
SELECT * FROM Tbl WHERE Name NOT LIKE '%Ali' --not ends with Ali
SELECT * FROM Tbl WHERE Name NOT LIKE 'Ali%' --not starts with Ali
SELECT * FROM Tbl WHERE Name <> 'Ali' --not equals to Ali
SELECT * FROM Tbl WHERE Name NOT LIKE 'Ali' --same as above



If your requirement is something else, please let me know.

Thanks


There are two reasons your query doesn't work.

Firstly [^Ali] is a string not a column so it needs to be surrounded by single-quotes '[^Ali]'

Secondly all you have included is the character set that must not match, you haven't included anything to match against. So try this instead

select * from Tbl where Name like '%[^Ali]%'


这篇关于为什么[^ ali]不能像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆