簡體   English   中英

如何計算每個不同值的出現

[英]How to count occurrences of each distinct value

我目前使用以下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
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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM