0
In Mysql I have a table called contact_status:
id | id_contato | detalhamento_id
1 | 1 | 2
2 | 1 | 3
3 | 2 | 4
4 | 2 | 2
5 | 2 | 1
6 | 3 | 2
7 | 4 | 4
8 | 5 | 4
In it is recorded all the contacts of attendance of the site, and also whenever a status is modified (for history). What I need now is to list the total details of each type. I managed with GROUP BY without problems. But it is not the right one. Because it also takes duplicate registrations (if a user has modified status). Then you would need to take only the details_id of each user, but the latter, with the larger ID. What I need to be shown is this:
detalhamento 1 - 1 ocorrência
detalhamento 2 - 1 ocorrência
detalhamento 3 - 1 ocorrência
detalhamento 4 - 2 ocorrência
How to do?
I think that question and answer might help you. Take a look there: https://answall.com/questions/233166/selectr-firstregister-dentro-de-umasegmenta%C3%A7%C3%a3o-no-sql-server/233176#233176
– Alexandre Cavaloti