hi i have frame this query and i encountered a error
like this.i have tried many but no result .i have modified query then its showing another error.
Failed to prepare the following query
Error preparing SQL statement.
SQL error #1:Syntax error: Encountered "MONTH" at line 4, column 46.
SELECT distinct productline as StringFact,orderdate,
SUM(CASE WHEN DATE(orderdate) between
(DATE_FORMAT(DATE_ADD(orderdate,INTERVAL -12 MONTH),'%Y-m%-01'))
AND (DATE_FORMAT(DATE_ADD(orderdate,INTERVAL -11 MONTH),'%Y-m%-01')) THEN BUY END) AS PREVYEAR,
SUM(CASE WHEN DATE(orderdate) between
(DATE_FORMAT(DATE_ADD(CURDATE(),INTERVAL 0 MONTH),'%Y-m%-01'))
AND (DATE_FORMAT(DATE_ADD(orderdate,INTERVAL 0 MONTH),'%Y-m%-01')) THEN BUY END) AS CURRENTMONTH,
SUM(CASE WHEN DATE(orderdate) between
(DATE_FORMAT(DATE_ADD(CURDATE(),INTERVAL -1 MONTH),'%Y-m%-01'))
AND (DATE_FORMAT(DATE_ADD(orderdate,INTERVAL -1 MONTH),'%Y-m%-01')) THEN BUY END) AS LASTMONTH
from (select orderdate,productline as StringFact,
sum(QUANTITYINSTOCK + BUYPRICE) as BUY,
sum(QUANTITYORDERED * PRICEEACH) as MSRP
from customers, orders, orderdetails, products
where customers.customernumber = orders.customernumber
and orders.ordernumber = orderdetails.ordernumber
and orderdetails.productcode = products.productcode
Group By productline,orderdate
)
Group By productline,orderdate