Insert column with mysql function

Asked

Viewed 90 times

0

Good morning,

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

I have a column called ID and it’s a history table, so this id repeats a few times I wanted a column that returned how many times this id repeated, example:

inserir a descrição da imagem aqui

THERE IS HOW?

1 answer

1

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.