gpt4 book ai didi

mysql - 表中日期的位置

转载 作者:行者123 更新时间:2023-11-29 06:27:55 25 4
gpt4 key购买 nike

我的 table 看起来像:

EmiDate    | EmiAmt | PaidDate   | PaidAmt 
-----------+--------+------------+--------
2019-01-05 | 7500 | 2019-01-05 | 7500
2019-01-06 | 7500 | 2019-01-06 | 7500
2019-01-07 | 7500 | null | null
2019-01-08 | 7500 | 2019-05-08 | 6500
2019-01-09 | 7500 | null | null
2019-01-10 | 7500 | null | null

我想在日期“2019-07-31”获取 SUM(EmiAmt)SUM(PaidAmt)。结果应如下所示:

22500 | 15000

我的尝试是:

SELECT SUM(EmiAmt)
, CASE WHEN PaidDate <= '2019-07-01' THEN SUM(PaidAmt) END
FROM tbl_Emi
WHERE EMIDate <= '2019-07-31';

这给了我“非聚合列”的错误。

最佳答案

我想你会在下面找到

select sum(EmiAmt),  sum(case when PaidDate  <='2019-07-01' then  PaidAmt else 0 end )
from tbl_Emi
where EMIDate <='2019-07-31';

关于mysql - 表中日期的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58429825/

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