Hi, I have written this query.
SELECT cl_brands.name AS Brand,DATE_FORMAT(cl_doctor_call.date_entered,'%b%y')AS MonthYear,
SUM(FIND_IN_SET(CONCAT('^',cl_brands.id,'^'),cl_doctor_call_cstm.brand_discussed_c))AS No_Times_Brand_Discussed
FROM cl_doctor_call LEFT JOIN cl_doctor_call_cstm ON
cl_doctor_call.id=cl_doctor_call_cstm.id_c
LEFT JOIN cl_brands ON
CONCAT('^',cl_brands.id,'^') LIKE CONCAT(cl_doctor_call_cstm.brand_discussed_c, '%' )
WHERE (cl_doctor_call.date_entered)
BETWEEN CURDATE()-INTERVAL 3 MONTH AND CURDATE()
GROUP BY cl_brands.name,MonthYear
ORDER BY No_Times_Brand_Discussed DESC limit 1
This query gives us highest brand discussed with brand name and monthyear.
Eg:
Brand Monthyear No_Times_Brand_Discussed
x Nov11 5
Now i want show the brand discussed details of ‘‘same brand’’ for last 2 months (that means my query should return me results for same brand details for more last 2 months) so my result would be like that
Brand Monthyear No_Times_Brand_Discussed
x Nov11 5
x Oct11 0
x Sep11 1
Tell me how can I modify my above query so that it will give me this result