id name text 1 apple hi 2 apple hello 3 apple good morning 4 betty hello 5 betty good afternoon
你好,讓我們說我有這個表是什麼得到類似的行數以最有效的/簡單的SQL這種情況下,有多少文本爲每名這樣的,我得到的結果合併成1個表:
name textcount apple 3 betty 2
id name text 1 apple hi 2 apple hello 3 apple good morning 4 betty hello 5 betty good afternoon
你好,讓我們說我有這個表是什麼得到類似的行數以最有效的/簡單的SQL這種情況下,有多少文本爲每名這樣的,我得到的結果合併成1個表:
name textcount apple 3 betty 2
select name, count(*) from Table1 group by name
你需要在SQL「聚合函數」讀了。一個參考是在這裏:http://oreilly.com/catalog/sqlnut/chapter/ch04.html
說,我有一個類似的表像你:
id name text
1 apple hi
2 apple hello
3 orange bye
4 orange how do you do
5 vodafone good evening
6 orange good afternoon
最簡單的查詢,以獲取根據表中的每個名稱文本的數量將是:
QUERY :
選擇的名字,COUNT(文本)從TABLE_2組 count_text_for_name個按名稱
結果:
name count_text_for_name
apple 2
orange 3
vodafone 1
啊,IC。我對功能不熟悉的羣體,時間做更多的閱讀。非常感謝! – codingnoob 2010-11-09 08:20:00