我無法成功編寫此查詢,但尚未找到任何資源。統計一列的重複次數
我有一個兩列的表。該表看起來有點像這樣:
|student|teacher|
| 5314 | 656 |
| 4189 | 671 |
| 4506 | 671 |
| 4515 | 671 |
| 3754 | 756 |
| 3760 | 756 |
| 1066 | 781 |
我想要的結果集是這樣的:
|teacher|count|
| 656 | 1 |
| 671 | 3 |
| 756 | 2 |
| 781 | 1 |
任何暗示,真是不勝感激。
好的地方開始閱讀:http://en.wikipedia.org/wiki/Aggregate_function和http://en.wikipedia.org/wiki/SQL#Queries – 2014-10-28 19:35:22
這兩個不同的表? – 2014-10-28 19:35:46
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html查看COUNT示例。 – Mihai 2014-10-28 19:41:06