title: Error #1064 in MySQL syntax
body: <p>I wrote one sql case condition query for view of mysql but I got error:</p>
  
  <pre><code>#1064 - You have an error in your SQL syntax;error at AS `total_amount_paid`, at line 3
  </code></pre>
  
  <p>The following is my code:</p>
  
  <pre><code>create or replace ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vw_customer_payment_status` AS select `p`.`customer_id` AS `customer_id`,
  concat(`l`.`first_name`,'',`l`.`last_name`) AS `customer_name`,
  sum(CASE WHEN l.lead_id = p.customer_id THEN`p`.`payment_amount`) AS `total_amount_paid`,
  sum(CASE WHEN l.lead_id = c.customer_id THEN `c`.`pending`) AS `total_amount_due`,
  (sum(`p`.`payment_amount`) - sum(`c`.`pending`)) AS `difference`,
  if(((sum(`p`.`payment_amount`) - sum(`c`.`pending`)) &gt; 0),0,1) AS `status` 
  from ((`tbl_leads` `l` join `tbl_customer_payments` `p`) 
  join `tbl_customer_payment_schedule` `c` 
  on((`l`.`lead_id` = `p`.`customer_id`)))
  </code></pre>