I have a select statement (working)
Select * FROM
(SELECT id, type, color, product,
SUM(Quantity) AS TotalQuantity,
MAX(Date) AS LatestDate
FROM inventory
GROUP BY id, color, type)
AS alias
WHERE TotalQuantity > 0
I am trying to add a WHERE clause to the Max(Date) but I am not having any luck:
I thought I would just change it to: MAX(Date) AS LatestDate WHERE stock = 1 But that does not work.
Not Working:
Select * FROM
(SELECT id, type, color, product,
SUM(Quantity) AS TotalQuantity,
/* Problem Here */ MAX(Date) AS LatestDate WHERE stock = 1
FROM inventory
GROUP BY id, color, type)
AS alias
WHERE TotalQuantity > 0
It will find the max dates for
stock = 1ornullif there is no such rows