SELECT pd.DC_Date, SUM(pd.Quantity-pd.Credit_Quantity) AS 'Sales'
FROM past_year_data PD
INNER JOIN idash_tb2_product_list PL ON PD.Product_Name = PL.Product_Name
WHERE PD.Branch_Name = 'Delhi'
AND DATE_FORMAT(STR_TO_DATE(DC_Date,'%m'), '%M') = DATE_FORMAT(STR_TO_DATE('7/31/2017', '%m'), '%M')
这就是我想要做的。
答案 0 :(得分:0)
您可以将String
转换为Date
并使用BETWEEN
和DATE_ADD
功能进行比较,例如:
SELECT pd.DC_Date,sum(pd.Quantity-pd.Credit_Quantity) AS 'Sales'
FROM past_year_data pd
JOIN idash_tb2_product_list PL ON PD.Product_Name=PL.Product_Name
WHERE pd.Branch_Name = 'Delhi' AND
STR_TO_DATE(DC_Date,'%m') BETWEEN DATE_ADD(NOW(), INTERVAL -12 MONTH) AND NOW();