SQL query to get count of each fileid entry in table
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
精彩评论