I need to make a select that brings me which customers I 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'
It 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 client with code 27 bought only in 2016 and is a list of clients of this type that I need.