How to total the number of records per Category using a VIEW SQL SERVER

Asked

Viewed 116 times

1

Good night. I’m not finding a way to, using or just calling a VIEW, count how many teachers there are in a certain category, whose output should be the category and the amount.

The VIEW I made is as follows:

CREATE VIEW VMostraProfessor AS
SELECT pro_nome AS Nome, cat_nome AS Categoria, tit_nome AS Titulação, 
CONVERT(VARCHAR(10), pro_nascimento, 103) AS Nascimento, cid_nome AS Cidade, pro_sexo AS Sexo FROM Professor p
    inner join categoria c ON c.cat_id = p.cat_id
    inner join titulacao t ON t.tit_id = p.tit_id
    inner join cidade cd ON cd.cid_ID = p.cid_id;

Can you do this on the call or within the view? (Preferably on the call)

Saída gerada pela VIEW

Grateful for the help!

1 answer

1


SELECT cmp.categoria,
       COUNT(1) AS quantidade
  FROM VMostraProfessor cmp
 GROUP BY cmp.categoria

Browser other questions tagged

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