1

IDとテキストフィールドがあります。

完全に一致する単語を検索するか、単一のmysqlクエリを使用して文字列内の単語で開始する必要があります。

例:select * from tablename where textfield like "%cam%. これは、camが単一のどこかにあるすべてのテキストIDを返します。

しかし、私は文の単一の単語を分割することによって照会できる結果を取得する必要があります。

IDテキスト

1 Camel_walk.
2 camel does drink water.
3 does Camel_store water.
4 In deset people can find_camel
5 this will not return

select * from tablename where textfield like "%camel%. 最初の1、2、3、4を返すようにクエリすると

しかし、私は単語がラクダで始まるIDを取得する必要があります

1)select * from tablename where textfield like "Camel%"
return 1,3 ( which is not working for me)
or even
2)select * from tablename where textfield like "%Camel"
return 4

これらの2つのクエリが機能していません

ありがとう

4

4 に答える 4

2

SQLのようなクエリでキャメル(適切な)ケースを使用すると、文字列では大文字と小文字が区別される文字列の一致が検出されますが、「camel」と「CAMEL」はキャメル/ CAMEL /Camelを検索します...など(大文字と小文字を区別しない一致)

select id from tablename where text like "%Camel%"1,3を返します。

select id from tablename where text like "%camel"4を返します。

select id from tablename where text like "%camel%"1,2,3,4を返します。

select id from tablename where text like "Camel%"1を返します。

select id from tablename where text like "camel%"1,2を返します。

select id from tablename where text like "camel %"(「camel」と「%」の間のスペース)は2を返します。

文字列の場合の違いに注意してください。

于 2013-02-21T06:14:55.637 に答える
0
select * from tablename where textfield like "Camel%" or textfield like ' %Camel'

%2番目の状態の前のスペースに注意してください。これらの2つの条件は、文字列で単語が始まるときに一致Camelします。最初の単語であるかどうかは関係ありません。

于 2013-02-21T05:49:40.630 に答える
0

これはすべての場合に機能するはずです

SELECT id
  from tablename
 WHERE textfield like '%[^A-z^0-9]Camel%' -- In the middle of a sentence
    OR textfield like 'Camel%'            -- At the beginning of a sentence
于 2013-02-21T05:56:21.203 に答える
0

ユーザーの対戦

$ conditions [] = array( "MATCH(MODEL_name.fieldname)AGAINST('$ text' IN BOOLEAN MODE)");

于 2013-02-22T11:53:52.130 に答える