开发者

SQL query to get count of each fileid entry in table

开发者 https://www.devze.com 2023-03-07 13:38 出处:网络
I Have a table like given below, the table name is tag. id fileid == ====== 11 22 32 42 53 63 73 I need to find the number of occurrences of each fileId. So the output need to be something

I Have a table like given below, the table name is tag.

id fileid 
== ======
 1   1
 2   2
 3   2
 4   2
 5   3
 6   3
 7   3

I need to find the number of occurrences of each fileId. So the output need to be something like this:

fileId coun开发者_开发技巧t
====== =====
  1      1
  2      3
  3      3

Can somebody help me with writing this MySQL query?


That would be:

select fileId, count(*)
from tag
group by fileId
order by fileId

The group by will aggregate rows with the same fileId value and the count(*) will count those rows for each.


try

    SELECT fieldId, COUNT(Id) AS count FROM tag GROUP BY fieldId
0

精彩评论

暂无评论...
验证码 换一张
取 消