title: I need to write a query in MySQL with multiple case and a single join that makes me error
body: <pre><code>SELECT COUNT(CASE WHEN YEAR(lead_date_time)='2020-03-04' AND JOIN t_settings ts ON ld.`lead_type`=ts.`setting_id` END) AS callsmade
         COUNT(CASE WHEN YEAR(lead_date_time)='2020-02-04' THEN ld.soft_delete ='n' END) AS leads,
         COUNT(CASE WHEN lead_followup_date!='0000-00-00' AND YEAR(lead_date_time)='2020-03-04' 
      AND DATE(lead_followup_date) ='2020-02-04' THEN ld.soft_delete ='n' END) AS todaysappointments ,
    COUNT(CASE WHEN lead_followup_date !='0000-00-00' AND YEAR(lead_date_time)='".$seleted_year."' 
      AND DATE(lead_followup_date) &gt;'2020-02-04' THEN ld.soft_delete ='n' END) AS upcomingappointments,
    COUNT(CASE WHEN lead_status ='Billed' AND YEAR(lead_date_time)='2020-03-04' THEN ld.soft_delete ='n' END) AS billedleads,
    COUNT(CASE WHEN lead_status ='qualified' AND YEAR(lead_date_time)='2020-03-04' THEN ld.soft_delete ='n' END) AS qualifiedleads,
    COUNT(CASE WHEN lead_followup_date !='0000-00-00 00:00:00' AND ((lead_assigned_to = '1') OR (ld.createdby ='1'))
      AND DATE(lead_followup_date) &gt;='2020-03-01' THEN ld.soft_delete ='n' END) AS appointments,
    COUNT(CASE WHEN lead_followup_date !='0000-00-00 00:00:00' AND ((lead_assigned_to = '1') OR (ld.createdby ='1'))
      AND DATE(lead_followup_date) &gt;='2020-03-01' THEN ld.soft_delete ='n' END) AS followup,
    COUNT(CASE WHEN lead_status ='Billed' AND ((lead_assigned_to = '1') OR (ld.createdby ='1'))
      THEN ld.soft_delete ='n' END) AS prospects
  
   FROM t_lead_details ld 
  
   WHERE ts.soft_delete='n'
  </code></pre>