How to count the number of records of a selection in a table

Asked

Viewed 4,982 times

1

I made a selection of all the results of a table. What I need is to show the amount of these results. In my case, I need to show you how many different specialties there are

SELECT "especialidade" FROM funcionarios GROUP BY "especialidade"

inserir a descrição da imagem aqui

2 answers

5


For "How many different specialties there are", Simple:

select 
    count(distinct especialidade) as qtd_especialidade
from funcionarios

or to "How many records there are by specialty:

select 
    especialidade,
    count(*) as qtd
from funcionarios group by especialidade
  • 1

    It worked! And how do I rename the column from there?

  • I changed the answer, see

  • @Diegosoares, remember to mark the answer as correct, if solved the problem ;)

1

@Diegosoares You can use the following query:

1- Return total records select Especialidade = Count(distinct speciality) from employees

2- grouped by type of expertise select Qtd = Count(distinct specialty) specialty from employees Group by specialty

3- filtered by speciality select Qtd = Count(distinct specialty) Where especialidade = "filter to place" from employees

4- filtered and grouped select Qtd = Count(distinct specialty) Where speciality = "filter 1 to place" from employees Union all select Qtd = Count(distinct specialty) Where speciality = "filter 2 to place" from employees

5- various specialties select Qtd = Count(distinct specialty) Where especialidade in ("filter to be put", "filter 2") from employees

Browser other questions tagged

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