2
I need help to create a select, I have 4 tables (commission, person, request, pedidoitem). So I need to bring in all the people and their goal values even if they don’t have values yet. I made a select the problem that it does not return the person when there is no request for this person.
I want it to return for example: person name/ meta/ value achieved
my code is like this so far:
SELECT
[PESSOA].[Fantasia] AS PESSOA,
[METAS].[MetaValorMinimoBase] AS META,
SUM(ISNULL(PDV_PedidoItemValorTotal,0)) AS Valor
FROM COM_METAS
FULL JOIN PESSOA ON METAS.MetaRepCod = PESSOA.Codigo
LEFT JOIN PEDIDO ON PESSOA.Codigo = PEDIDO.PedidoRepresentante
LEFT JOIN PEDIDOITEM ON PEDIDO.PedidoCodigo = PEDIDOITEM.PedidoCodigo
WHERE PEDIDO.PedidoExcluido = 'N' and
PEDIDO.PedidoTipoMovimentoCodigo IN (1,5,6) AND
PEDIDO.PedidoSituacao IN ('A','B','O','T','E')AND
PEDIDO.PedidoDataEmissao BETWEEN '01/06/2018' AND '05/06/2018'
GROUP BY
[PESSOA].[Fantasia],
[METAS].[MetaValorMinimoBase]
Order by [PESSOA].[Fantasia]
RETURN :
JOÃO |60000 |697569
PEDRO |240000 |1374417
MARIA |60000 |67995
FRANCISCO |200000 |2376976
ZÉ |NULL |23423
ROMARIO |20000 |NULL
I want you to bring me other people who have goals even if they have no value.
It even returns people with meta null, but I want to return also those that have value (of the requests) null or 0 in the case.
Related (duplicate?): What is the difference between INNER JOIN and OUTER JOIN?
– Homer Simpson