0
Good evening I’m creating a referral system, But the query result does not return users with zero indications
Here is my select
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
which database, mysql?
– Ricardo Pontual
in fact, the function and area columns should be in the
group by
, otherwise it will error in your select– Ricardo Pontual
The database is Mysql, is working, but the collaborators who will not indicate does not return in the query
– Anderson Pimenta
Example: Anderson 0 indications, maria 3 indications
– Anderson Pimenta
without seeing the table data is difficult to say what it is, if putting an example of the data becomes easier to help
– Ricardo Pontual
I can’t send photos,
– Anderson Pimenta
CREATE TABLE
col
(id
int(10) NOT NULL,nome
varchar(90) NOT NULL,funcao
varchar(90) NOT NULL,area
varchar(90) NOT NULL, PRIMARY KEY (id
) CREATE TABLE IF NOT EXISTSindicacao
(nome_cli
varchar(120) NOT NULL,cpf_cli
varchar(14) NOT NULL,id_colaborador
int(10) NOT NULL,data_ind
datetime DEFAULT CURRENT_TIMESTAMP,status
int(2) NOT NULL DEFAULT '0', PRIMARY KEY (cpf_cli
), KEYid_colaborador
(id_colaborador
)– Anderson Pimenta
these are my related tables col(contributor) and indication
– Anderson Pimenta