Insert column with mysql function

0

Good morning,

I'm a beginner and I'm having a hard time.

I have a column named ID and it is a history table, so this id repeats a few times I wanted a column to return how many times that id was repeated, eg:

HOW?

    
asked by anonymous 06.04.2018 / 16:27

1 answer

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, eg

SELECT
    ID,
    COUNT(ID) AS total
FROM
    historico
GROUP BY
    ID
ORDER BY
    2

In the example above, in addition to grouping and counting elements, you are sorting through the second column.

    
06.04.2018 / 16:59