gpt4 book ai didi

mysql - mysql中的总金额

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

我有这个请求,但效果不佳。

select date_format(date, "%Y-%m-%d") as month,
sum(value) as total
from :table_orders_sales_commission
where date_sub(now(), interval 12 month) <= date
group by month

结果是:

2017-04-02 4.6440
2017-04-03 2.6200

如何求一个月的总和(4.644+2.62)?

最佳答案

使用 MONTH 函数并将其用作分组依据

select MONTH(date_format(date, "%Y-%m-%d")) as month,
sum(value) as total
from :table_orders_sales_commission
where date_sub(now(), interval 12 month) <= date
group by MONTH(date_format(date, "%Y-%m-%d"))

关于mysql - mysql中的总金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43186676/

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