gpt4 book ai didi

mysql - 返回 1 行而不是多行

转载 作者:行者123 更新时间:2023-11-29 05:13:03 25 4
gpt4 key购买 nike

您好,我有一个查询,目前返回 4 行数据。

SELECT (case when a.duedate < '2016-04-26' and a.total_paid > 0 
then count(a.duedate)
else 0 end) as paidWithDelay,
(case when a.duedate < '2016-04-26' and a.total_paid = 0
then count(a.duedate)
else 0 end) as Overdue,
(case when a.duedate > '2016-04-26' and a.total_paid > 0
then count(a.duedate)
else 0 end) as paidOnTime,
(case when a.duedate > '2016-04-26' and a.total_paid = 0
then count(a.duedate)
else 0 end) as waitingForPayment
FROM payment_plan a
where a.payor_orig_id = 611 and a.UPDATE_DT is null
group by a.duedate;

如图所示。 enter image description here基本上我想要的是只返回一行像这样paidWithDelay 2,过期 1,paidontime 0 和 waitingForPayment 1,我尝试写 sum front of case ,但没​​有成功。

最佳答案

    select sum(paidwithdelay)paidwithydelay,sum(overdue)overdue,sum(paidontime)paidontime,sum(waitingforpayment)waitingforpayment 
from (SELECT (case when a.duedate < '2016-04-26' and a.total_paid > 0
then count(a.duedate)
else 0 end) as paidWithDelay,
(case when a.duedate < '2016-04-26' and a.total_paid = 0
then count(a.duedate)
else 0 end) as Overdue,
(case when a.duedate > '2016-04-26' and a.total_paid > 0
then count(a.duedate)
else 0 end) as paidOnTime,
(case when a.duedate > '2016-04-26' and a.total_paid = 0
then count(a.duedate)
else 0 end) as waitingForPayment
FROM payment_plan a
where a.payor_orig_id = 611 and a.UPDATE_DT is null
group by a.duedate)temp;

关于mysql - 返回 1 行而不是多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36859965/

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