gpt4 book ai didi

mysql - 查询中的列总和

转载 作者:行者123 更新时间:2023-12-01 00:18:37 25 4
gpt4 key购买 nike

我有这个问题

`SELECT order_customFields.order_customFields_delivery_method,

sum(case `order`.order_status when 'paid' then 1 else 0 end) paid,
sum(case `order`.order_status when 'later' then 1 else 0 end) later
FROM order_customFields
INNER JOIN `order` ON order_customFields.order_id = `order`.order_id

where `order`.order_createdAt >= date_sub(date_sub(curdate(), interval day(curdate()) - 1 day), interval 1 month)
and `order`.order_createdAt < date_sub(curdate(), interval day(curdate()) - 1 day)
AND order_customFields.order_customFields_delivery_method in('a','b','c','d','e')
GROUP BY
order_customFields.order_customFields_delivery_method`

如何在此查询中获取列 paidlater 的总和?像这样example

最佳答案

如果你想求两列之和,只需使用IN

sum(case when `order`.order_status in ('paid', 'later') then 1 end)

关于mysql - 查询中的列总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42064223/

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