filter between two dates with join

0

I have two tables: col (contributor) and Indicacao .

I made select to know how many leads each employee has. It is working but I can not filter by date using between .

SELECT c.id, c.nome, funcao, area, count(p.cpf_cli) AS quantidade FROM 
col c LEFT JOIN
indicacao p ON p.id_colaborador = c.id GROUP BY c.id, c.nome ORDER BY
c.nome

I tried with between but it did not work.

SELECT c.id, c.nome, funcao, area, count(p.cpf_cli) AS quantidade FROM 
col c LEFT JOIN
indicacao p ON p.id_colaborador = c.id GROUP BY c.id, c.nome ORDER BY
c.nome WHERE indicacao.data_ind BETWEEN '2018/09/20' AND '2018/09/21'
    
asked by anonymous 22.09.2018 / 02:45

1 answer

0

Always remember that reserved words like GROUP BY and ORDER BY come after WHERE .

Another thing is that every column that is not being used in grouping functions with SUM , COUNT , AVG etc, needs to be listed in the GROUP BY clause.

SELECT 
   c.id, 
   c.nome, 
   funcao, 
   area, 
   count(p.cpf_cli) AS quantidade 
FROM col c 
LEFT JOIN indicacao p 
   ON p.id_colaborador = c.id 
WHERE 
   indicacao.data_ind BETWEEN '2018/09/20' AND '2018/09/21'
GROUP BY 
   c.id, c.nome 
ORDER BY
   c.nome
    
22.09.2018 / 03:18