2012-08-10 158 views
0

我有這個問題,我不知道從哪裏開始。
例如,我在我的數據庫有這個[這只是示例數據庫 ]按字母順序排列單詞列表並按首字母順序篩選

id word 
1 adore 
2 and 
3 apple 
4 asore 
5 banana 
6 bate 
7 beat 
8 busy 

我怎麼能對它進行排序和過濾,所以我只能查看單詞,「A」開頭的?

id word 
1 adore 
2 and 
3 apple 
4 asore 

回答

0
select id, word 
from your_table 
where word like 'a%' 
order by id 

select id, word 
from your_table 
where substring(word, 1, 1) = 'a' 
order by id 
+0

非常感謝你 – Butternut 2012-08-10 16:04:02

1

您可以使用SQL-LIKE語句。

SQL:SELECT DISTINCT word FROM Table WHERE word LIKE 'A%' 這隻返回以a開頭的單詞。

1

這比您想象的要簡單得多。您可以使用SQL LIKE operator

SELECT * FROM table WHERE word LIKE 'a%' ORDER BY word; 
+0

非常感謝你 – Butternut 2012-08-10 15:42:24