帮助我进行SQL查询. [英] Help me with an SQL query..

查看:95
本文介绍了帮助我进行SQL查询.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
我已经创建了这样的表:

Hi everyone!
I have created such table:

CREATE TABLE Person
         (
             PersonID  uniqueidentifier,
             FirstName  VARCHAR(80),
             LastName   VARCHAR(100),
         );



我想找到所有姓氏中没有字母"a"的人.我查询:



I want to find all the persons whose lastname has no letter "a" in their lastnames. I query:

SELECT FirstName, LastName
         FROM Person
         WHERE   LastName NOT LIKE ''%a%'';


/////可以正常工作
但是当我这样查询时


///// It works fine
But when i quey like that

SELECT  FirstName, LastName
         FROM   Person
         WHERE   LastName  LIKE ''%[^a]%'';



它不起作用-我看到姓氏带有一个"a"字母....
这两个查询有什么区别?

还有一个问题,如何选择所有
的人 姓氏只有一个"a"字母,只有两个"a"字母,....



It doesn''t work - I see the lastnames with an "a" letter....
What''s the difference between these two queries??

One more question, how to select all the persons whose
last name has ONLY ONE "a" letter, ONLY TWO "a" letters, ....

推荐答案

第二个查询返回所有包含一个字母的名称没有"a".因此,"Dave"包含3个字母,而没有"a",因此它将显示在结果中.
The second query returns all names with contains a letter which is no ''a''. So ''Dave'' contains 3 letter which ar no ''a'', so it will show up in the results.


就像不使用正则表达式语法一样,为什么第二个未能获得预期的结果

[edit]
您是正确的,例如不支持正则表达式.但是第二个SQL查询中的语法很好.
Like does not use regular expression syntax, that''s why the second one fails to get the expected results

[edit]
You are right about like does not support regular expression. But the syntac in the second SQL query is good.


这篇关于帮助我进行SQL查询.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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