SQL matni to'la so'z

Bilaman, bu so'rov oqni o'z ichiga olgan barcha qatorlarni qaytaradi:

SELECT COUNT(*) FROM MyTable WHERE Title like '%white%'

Ammo "oq gul" kabi qatorlarni "whiteroz" kabi emas. Ushbu so'rovni faqat bitta "oq" so'z sifatida olish uchun qanday o'zgartirish mumkin? Oldindan rahmat.

1

10 javoblar

Har ikki tomonning kosmik belgisi bilan so'zni topib, uni sinab ko'ring.

SELECT COUNT(*) FROM MyTable WHERE ' ' + Title + ' ' like '% white %'

Ikkala tomon nomiga joy ajratish so'zning boshi yoki oxirida keladigan vaziyatlarni qoplashdir.

3
qo'shib qo'ydi

Har ikki tomonning kosmik belgisi bilan so'zni topib, uni sinab ko'ring.

SELECT COUNT(*) FROM MyTable WHERE ' ' + Title + ' ' like '% white %'

Ikkala tomon nomiga joy ajratish so'zning boshi yoki oxirida keladigan vaziyatlarni qoplashdir.

3
qo'shib qo'ydi

Boshqa javoblar punktatsiyani hisobga olmaydilar.

DECLARE @Table TABLE (
    Title NVARCHAR(4000)
)

INSERT INTO @Table (Title) SELECT 'White Christmas was a song.'
INSERT INTO @Table (Title) SELECT 'I''m dreaming of a white Christmas.'
INSERT INTO @Table (Title) SELECT 'The snow was white.'
INSERT INTO @Table (Title) SELECT 'Whitewolves are dangerous.'
INSERT INTO @Table (Title) SELECT 'Snowwhite was a female.'


SELECT *
FROM (
    SELECT Title FROM @Table
    WHERE Title LIKE '%white%'
) match
WHERE Title NOT LIKE '%white[a-z]%'
AND Title NOT LIKE '%[a-z]white%'
3
qo'shib qo'ydi

Boshqa javoblar punktatsiyani hisobga olmaydilar.

DECLARE @Table TABLE (
    Title NVARCHAR(4000)
)

INSERT INTO @Table (Title) SELECT 'White Christmas was a song.'
INSERT INTO @Table (Title) SELECT 'I''m dreaming of a white Christmas.'
INSERT INTO @Table (Title) SELECT 'The snow was white.'
INSERT INTO @Table (Title) SELECT 'Whitewolves are dangerous.'
INSERT INTO @Table (Title) SELECT 'Snowwhite was a female.'


SELECT *
FROM (
    SELECT Title FROM @Table
    WHERE Title LIKE '%white%'
) match
WHERE Title NOT LIKE '%white[a-z]%'
AND Title NOT LIKE '%[a-z]white%'
3
qo'shib qo'ydi

So'zlarni bo'shliqlar bilan ajratib qo'ygan holda, quyidagilarni qilishingiz mumkin:

WHERE ' ' + Title + ' ' like '% white %'

Shu bilan bir qatorda, to'liq matn terish qobiliyatini talab qilishingiz mumkin.

1
qo'shib qo'ydi

So'zlarni bo'shliqlar bilan ajratib qo'ygan holda, quyidagilarni qilishingiz mumkin:

WHERE ' ' + Title + ' ' like '% white %'

Shu bilan bir qatorda, to'liq matn terish qobiliyatini talab qilishingiz mumkin.

1
qo'shib qo'ydi

"Yo'q" iborasi kabi tinish belgilarini o'z ichiga oladi:

select title 
from t
where ' '+title+' ' like '%[^a-z]white[^a-z]%'

rextester demo: http://rextester.com/DBVH10759

create table t (title varchar(32));
insert into t values
 ('white')
,('whiteboard')
,('offwhite')
,('white house')
,('something white.')

select title 
from t
where ' '+title+' ' like '%[^a-z]white[^a-z]%'

qaytaradi

+------------------+
|      title       |
+------------------+
| white            |
| white house      |
| something white. |
+------------------+
0
qo'shib qo'ydi

"Yo'q" iborasi kabi tinish belgilarini o'z ichiga oladi:

select title 
from t
where ' '+title+' ' like '%[^a-z]white[^a-z]%'

rextester demo: http://rextester.com/DBVH10759

create table t (title varchar(32));
insert into t values
 ('white')
,('whiteboard')
,('offwhite')
,('white house')
,('something white.')

select title 
from t
where ' '+title+' ' like '%[^a-z]white[^a-z]%'

qaytaradi

+------------------+
|      title       |
+------------------+
| white            |
| white house      |
| something white. |
+------------------+
0
qo'shib qo'ydi

Siz nimani izlayotgan bo'lsangiz, men taxmin qilaman:

SELECT COUNT(*)
FROM MyTable
WHERE Title like '% white %'
  OR Title like '% white'
  OR Title like 'white %';
0
qo'shib qo'ydi

Siz nimani izlayotgan bo'lsangiz, men taxmin qilaman:

SELECT COUNT(*)
FROM MyTable
WHERE Title like '% white %'
  OR Title like '% white'
  OR Title like 'white %';
0
qo'shib qo'ydi