use SUCOS_VENDAS SELECT CPF, COUNT() FROM [NOTAS FISCAIS] WHERE YEAR(DATA) = 2016 GROUP BY CPF HAVING COUNT() < 2000
use SUCOS_VENDAS SELECT CPF, COUNT() FROM [NOTAS FISCAIS] WHERE YEAR(DATA) = 2016 GROUP BY CPF HAVING COUNT() < 2000
use SUCOS_VENDAS SELECT CPF, COUNT(*) as compras FROM [NOTAS FISCAIS] WHERE YEAR(DATA) = 2016 GROUP BY CPF HAVING COUNT(compras) > 2000