0
In a select statement you can use the GROUP BY command to group the values and then use the COUNT command to count the occurrences, example:
SELECT
ID,
COUNT(ID) AS total
FROM
historico
GROUP BY
ID
ORDER BY
2
In the above example, in addition to grouping and counting the elements, you are ordering by the second column.