top of page

COUNT | DISTINCT COUNT | SUM | GROUP BY

Atualizado: 18 de abr. de 2023


Exemplo 1:


Exemplo 2:




Exemplo 3:


--contagem por cargo do quadro ativo


SELECT DISTINCT


PFUNCAO.NOME AS CARGO,

COUNT(PFUNCAO.NOME) AS 'QNT'



FROM PFUNC(NOLOCK)

LEFT OUTER JOIN PFUNCAO(NOLOCK)

ON ((PFUNC.CODCOLIGADA = PFUNCAO.CODCOLIGADA)

AND (PFUNC.CODFUNCAO = PFUNCAO.CODIGO))

LEFT OUTER JOIN PFCOMPL(NOLOCK)

ON ((PFUNC.CODCOLIGADA = PFCOMPL.CODCOLIGADA)

AND (PFUNC.CHAPA = PFCOMPL.CHAPA))


LEFT OUTER JOIN PPESSOA(NOLOCK)

ON ((PFUNC.CODPESSOA = PPESSOA.CODIGO))

LEFT OUTER JOIN PTPFUNC(NOLOCK)

ON ((PFUNC.CODTIPO = PTPFUNC.CODCLIENTE))



WHERE


PFUNC.CODRECEBIMENTO <> 'O'

AND PFUNC.NOME <> 'AMANDA'

AND (PFUNC.CHAPA NOT LIKE '%T%'

AND PFUNC.CHAPA NOT LIKE '%A%'

AND PFUNC.CHAPA NOT LIKE '%D%'

AND PFUNC.CHAPA NOT LIKE '%c%'

AND PFUNC.CHAPA NOT LIKE '%DN%'

AND PFUNC.CHAPA NOT LIKE '%B%'

AND PFUNC.CHAPA NOT LIKE '%E%'

AND PFUNC.CHAPA NOT LIKE '22%'

AND PFUNC.DATADEMISSAO IS NULL)



GROUP BY PFUNCAO.NOME

ORDER BY QNT DESC




bottom of page