SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb MySql Query modify

    Hi, I have written this query.

    Code MySQL:
    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

  2. #2
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If anyone is having difficulty to understand my issue, let me know... I 'll try to explore it in another way....


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •