I am, currently switching my website from an access DB to mySQL. I am getting an error "Invalid use of group function" when trying to execute the code below:

SELECT Max(Orders.date) AS MaxOfdate, Count(Orders.ProductsID) AS CountOfProductsID,
Year(date) AS myyear, Month(date) AS mymonth, Dayofmonth(date) AS myday
FROM Orders GROUP BY Year(date), Month(date), Dayofmonth(date), Orders.ProductsID
HAVING (((Orders.ProductsID)=1)) ORDER BY Max(Orders.date)

Can someone help please.