Count database records without repeating

-1

I have a table that has several records with the same information, eg:

id |  nome      |  profissao
1     Carlos       Pedreiro
2     Jean         Garçon
3     Victor       Pedreiro
4     Ana Paula    Secretaria
5     Paula        Secretaria
6     Karina       Balconista

What I need to tell you is the amount of profession but without repeating it, in the example I gave you have 6 records, but it only has 4 different professions, that's what I need to tell you, I do not know how to tell you more without repeating

    
asked by anonymous 31.07.2018 / 15:18

1 answer

2

Do as follows:

SELECT
   t.profissao,
   COUNT(t.profissao) as total
FROM
   tabela t
GROUP BY
   t.profissao

No SELECT put COUNT(t.profissao) , grouping by the same field, ie GROUP BY t.profissao . In this way it will return the number of repetitions of each profession, and to know which profession belongs the amount shown, simply add the field profissao , as shown in query above.

The result of the query would be something like this:

total     |  profissao
2            Pedreiro
1            Garçon
2            Secretaria
1            Balconista
    
31.07.2018 / 15:26