1
I need to make a select that brings me which customers bought in 2016 and did not buy in 2017 and vice versa.
This is my select:
SELECT
tc.`cod-emitente` AS CODIGO,
tc.`nome-emit` AS CLIENTE,
fg.`ano` AS ANO
FROM tb_clientes tc
LEFT JOIN faturamento_global fg ON (tc.`cod-emitente` = fg.`cod-emitente`)
WHERE fg.`ano` >= 2016
GROUP BY fg.`cod-emitente`, fg.`ano`
He brings me the following:
CODIGO CLIENTE ANO
14 CLIENTE1 2016
14 CLIENTE1 2017
15 CLIENTE2 2016
15 CLIENTE2 2017
27 CLIENTE3 2016
35 CLIENTE4 2016
35 CLIENTE4 2017
Note that the customer with code 27 bought only in 2016 and is a list with customers of this type that I need.
You need to clarify your question a little by showing, for example, situations where your condition is satisfied.
– Sorack
You cannot put the data in this table in your question to facilitate understanding?
– Sorack
I executed this way, however, brought the result I put in the initial post, now I need to separate which customer bought in one year and not another.
– Mauricio Zambretti