gpt4 book ai didi

mysql - 查询计数行的总和(过去 30 天)

转载 作者:太空宇宙 更新时间:2023-11-03 10:56:12 27 4
gpt4 key购买 nike

我有这张表 p_payments。该表包含 payment_amountpayment_statuscreatedtime 列:

p_payments
____________________________
payment_status varchar(25)
payment_amount decimal(7,2)
createdtime datetime

我如何创建一个查询来计算过去 30 天的收入总和 WHERE payment_status = completed

我的 table

payments_status     payment_amount     createdtime
----------------------------------------------------------
Completed 1.00 2013-09-29 21:45:02
Denied 2.00
Failed 1.50
... etc

最佳答案

SELECT Sum(payment_amount) 
FROM p_payments
WHERE payments_status = 'completed'
AND createdtime >= Date_Sub(Curdate(), INTERVAL 30 day)

关于mysql - 查询计数行的总和(过去 30 天),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20530934/

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