gpt4 book ai didi

带条件的字段的 MySQL SUM,IF(SUM(bill_1) IS NULL, '99' , SUM(bill_1)) AS tot_bill_1

转载 作者:行者123 更新时间:2023-11-29 23:00:19 28 4
gpt4 key购买 nike

我想要 SUM(tot_bill_1+tot_bill_2) AS 总计,但这不起作用

SELECT *, 
IF(SUM(bill_1) IS NULL, '99', SUM(bill_1)) AS tot_bill_1,
IF(SUM(bill_2) IS NULL, '10', SUM(bill_2)) AS tot_bill_2,
SUM(tot_bill_1+tot_bill_2) AS total
FROM billing

有什么想法吗?

最佳答案

您可以使用子查询来做到这一点:

SELECT sum_bill1,
sum_bill2,
(sum_bill1 + sum_bill2) AS total
FROM
(SELECT COALESCE(sum(bill1), 99) AS sum_bill1,
COALESCE(sum(bill2), 10) AS sum_bill2
FROM billings) t

关于带条件的字段的 MySQL SUM,IF(SUM(bill_1) IS NULL, '99' , SUM(bill_1)) AS tot_bill_1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28523577/

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