gpt4 book ai didi

php - 在括号内使用 COALESCE 错误

转载 作者:行者123 更新时间:2023-11-29 19:45:33 25 4
gpt4 key购买 nike

select 
tele_plan.id as value,
tele_plan.plan_name as label,
tele_plan.plan_cost as c,
tele_plan.plan_details as d,
COALESCE ( tele_plan.plan_cost - sum(tele_payment_items.amount) as balance ,0) from `tele_plan_select`
inner join `tele_plan` on `tele_plan`.`id` = `tele_plan_select`.`teleplan_id`
left join `tele_payment_defs` on `tele_payment_defs`.`telereg_id` = `tele_plan_select`.`telereg_id`
left join `tele_payment_items` on `tele_payment_items`.`telepaymentdefs_id` = `tele_payment_defs`.`id`
and
`tele_payment_items`.`teleplan_id` = `tele_plan`.`id`
where `tele_plan_select`.`telereg_id` = 9
group by `tele_plan`.`id`

我在这里使用 Laravel 框架。我猜这里的问题在于COALESCE。我试图通过减去两列值来找到平衡。如果没有返回任何内容作为 balance ,则应将其设置为 0,这就是我正在尝试做的事情。

最佳答案

COALESCE 的用法是错误的。改变它就像

COALESCE (tele_plan.plan_cost, 0) - COALESCE(SUM(tele_payment_items.amount), 0) as  balance

关于php - 在括号内使用 COALESCE 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41015354/

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