2015-09-21 45 views
0

我現在從我的DB拉不同的「標籤」(小寫)的列表,用下面的SQL:如何計算每個不同的值的出現

SELECT DISTINCT(LOWER(tag)) AS tag FROM user.tags ORDER BY LOWER(tag); 

我想第二個列添加到我的結果,其統計每個標籤的出現次數。因此,不是又回到:

tag: 
'test' 
'sample' 
'example' 

我會得到:

tag:  count: 
'test'  3 
'sample' 2 
'example' 7 
+2

請在'組by'一些研究和'計數()'。 –

回答

1
SELECT LOWER(tag), COUNT(1) AS tag 
FROM user.tags 
GROUP BY LOWER(tag) 
--ORDER BY COUNT(1); -- if you want to order by the count 
相關問題