-1
I have 3 tables produto
, carrinhoProduto
and venda
I wanted to know the products that did not sell in the year 2015
:
SELECT p.idProduto,p.descricao as 'Produto',datepart(year,v.dataVenda) as 'Ano'
FROM Venda v
INNER JOIN CarrinhoProduto cp ON v.idCarrinho = cp.idCarrinho
LEFT JOIN Produto p ON p.idProduto = cp.idProduto
WHERE cp.idProduto IS NULL AND datepart(year,GETDATE()) = 2015
GROUP BY p.idProduto, p.descricao, v.dataVenda
The result is all the products that were not sold, that is, from always 2016+2015+....etc., but only wanted the 2015 ones.
What exactly is the type of your date field in the table?
– Kenny Rafael
Great, the guy’s date
– Dexter
@Dexter which database you are using?
– Sorack