gpt4 book ai didi

mysql - MySQL 语法中的错误#1064

转载 作者:行者123 更新时间:2023-11-29 23:25:58 24 4
gpt4 key购买 nike

我为 mysql View 编写了一个 sql 大小写条件查询,但出现错误:

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

以下是我的代码:

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`)))

最佳答案

您需要将 END CASE 添加到 CASE 语句中。就在右括号之前。

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`,

关于mysql - MySQL 语法中的错误#1064,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26965769/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com