I have the tables:
- reparableis
- projects
- contracts
- contracted_items
- control_contracts
I made this Query:
Select
a.qtd as quantidade_contratada,
b.pn,
c.numero_contrato,
count(d.id_pn) qtd_executada,
(a.qtd - count(d.id_pn)) saldo,
e.projeto
FROM
itens_contratados a
LEFT JOIN reparaveis b ON a.id_pn = b.id_pn
INNER JOIN contratos c ON a.id_contrato = c.id_contrato
INNER JOIN controle_contratos d ON a.id_pn = d.id_pn
INNER JOIN projetos e ON e.id_projeto = d.id_projeto and e.id_projeto = a.id_projeto
Where
d.status <> 'Cancelada' and d.status <> 'Aguardando Cancelamento'
GROUP BY
b.pn, e.projeto DESC
I have as a result what I need when there is a record in the controle_contratos
table, but I also need the query to show b.id_pn
( b.pn
Group By
) that does not appear in the controle_contratos
table, Where am I going wrong?