2013-04-25 41 views
0

我試圖獲得以特定字母開頭的書名列表。但是,我需要在標題開頭忽略「the」。例如,當我在查找以「a」開頭的標題時,此查詢應返回「the alamo」和「American history」。獲取字符串的首字母,無視「該」

我該怎麼做?

+0

SQL不太好,但是您可以隨時梳理每個標題,如果第一個字母是「the」,則忽略它並檢查標題中下一個單詞的第一個字母。 – David 2013-04-25 14:07:14

回答

3

使用

WHERE CASE WHEN SUBSTR(title, 1, 4) = 'the ' THEN SUBSTR(title, 5) ELSE title END LIKE '...' 

在您的查詢中,或使用模式。

2

試試這個查詢

select titles 
from tablename 
where titles like 'a%' 
or titles like 'the a%' 

編輯

select titles 
from tablename 
where REPLACE(titles,'the ','') like 'a%' 
+0

問題在於它不適用於字母「t」。 – 2013-04-25 14:11:36

+0

@GordonLinoff我想知道你想說什麼,可以解釋一下。 – Luv 2013-04-25 14:13:22

+0

您將在字母「T」上匹配「The Alamo」等標題。我不認爲OP希望這場比賽。 – 2013-04-25 14:16:08

2
... where title like 'a%' or title like 'the a%' 
相關問題