全文索引——contains 語法
,查詢結果受系統全文索引分詞的方法影響查詢結果會不全。
select * from a where contains(b,'"it"or"理論"')5257條記錄
select * from a where b like'%it%' or b like '%理論%' 5468條記錄
結論:需要精確查詢用like如產品搜尋,內容搜尋可以用contains提高效率。
我們通常在 where 子句中使用 contains ,就象這樣:select * from table_name where contains(fulltext_column,'search contents')。
我們通過例子來學習,假設有表 students,其中的 address 是全文字檢索的列。
1. 查詢住址在北京的學生
select student_id,student_name
from students
where contains( address, 'beijing' )
remark: beijing是乙個單詞,要用單引號括起來。
2. 查詢住址在河北省的學生
select student_id,student_name
from students
where contains( address, '"heibei province"' )
remark: hebei province是乙個片語,在單引號裡還要用雙引號括起來。
3. 查詢住址在河北省或北京的學生
select student_id,student_name
from students
where contains( address, '"heibei province" or beijing' )
remark: 可以指定邏輯操作符(包括 and ,and not,or )。
4. 查詢有 '南京路' 字樣的位址
select student_id,student_name
from students
where contains( address, 'nanjing near road' )
remark: 上面的查詢將返回包含 'nanjing road','nanjing east road','nanjing west road' 等字樣的位址。
a near b,就表示條件: a 靠近 b。
5. 查詢以 '湖' 開頭的位址
select student_id,student_name
from students
where contains( address, '"hu*"' )
remark: 上面的查詢將返回包含 'hubei','hunan' 等字樣的位址。
記住是 *,不是 %。
6. 類似加權的查詢
select student_id,student_name
from students
where contains( address, 'isabout (city weight (.8), county wright (.4))' )
remark: isabout 是這種查詢的關鍵字,weight 指定了乙個介於 0~1之間的數,類似係數(我的理解)。表示不同條件有不同的側重。
7. 單詞的多型查詢
select student_id,student_name
from students
where contains( address, 'formsof (inflectional,street)' )
remark: 查詢將返回包含 'street','streets'等字樣的位址。
對於動詞將返回它的不同的時態,如:dry,將返回 dry,dried,drying 等等。
以上例子都使用英文,不使用中文是因為有的查詢方式中文不支援,而且我的計算機是英文系統。
全文索引——contains 語法
我們通常在 where 子句中使用 contains ,就象這樣:select * from table_name where contains(fulltext_column,'search contents')。
如果你在選定欄位中查詢乙個匹配的直接使用
如:從company中檢查是否有test1的則:
select * from company
where contains(*,'test1')
如果要檢查的是兩個關鍵字,如是或地關係:
select * from company
where contains(*,'"北京" or "tttt"')
注意:關鍵字「北京」和「tttt」必須用"",包括起來,or代表兩個關鍵字之間是"或"的關係
如果是與的關係:
select * from company
where contains(*,'"北京" and "tttt"')
如果是三個關鍵字則:
關鍵字前的那個or或者and 表示跟其他關鍵字的關係
and 表示兩個詞是靠近的
Access中的SQL語句
access資料庫的sql語句教學 2009 07 01 20 50 47作者 網際網路瀏覽次數 229文字大小 大 中 小 引子 如何找到access資料庫的sql檢視 1 單擊下圖左側的 2 單擊上圖頂部的,彈出如下圖對話方塊 5 單擊 關閉 此時在選單中的檔案選單下面出現乙個sql的下拉框 6...
SQL中Case語句用法
case具有兩種格式。簡單case函式和case搜尋函式。簡單case函式case when 1 then 男 when 2 then 女 else 其他 end case搜尋函式 casewhen 1 then 男 when 2 then 女 else 其他 end 這兩種方式,可以實現相同的功能...
SQL語言的應用
access環境的sql語言的應用 一 實驗目的 1 掌握使用sql語句進行簡單查詢。2 掌握使用sql語句進行條件查詢。3 掌握使用sql語句進行多表查詢 4 熟練掌握 select語句編寫資料查詢的語句 二 實驗內容 1 根據給定的表,用sql的選擇語句selete來建立查詢。2 根據已建立的多...