简体   繁体   中英

Error #1064 in MySQL syntax

I wrote one sql case condition query for view of mysql but I got error:

#1064 - You have an error in your SQL syntax;error at AS `total_amount_paid`, at line 3

The following is my 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`)) > 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`)))

You need to add END CASE to your CASE statements. Right before the close parenthesis.

sum(CASE WHEN l.lead_id = p.customer_id THEN`p`.`payment_amount` END CASE) AS `total_amount_paid`,
sum(CASE WHEN l.lead_id = c.customer_id THEN `c`.`pending` END CASE) AS `total_amount_due`,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM