【Mysql】按季度查询结果数据累加

【Mysql】按季度查询结果数据累加,第1张

参考文档:

https://blog.csdn.net/homechao/article/details/81207551?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control

https://blog.csdn.net/chongmu2584/article/details/100738740?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242

换其他数据库一个 sum() over (partition by ... )就解决了..

mysql比较麻烦, 可以试下

select a.Daytime,sum(new_Role)

from (select distinct DATE_FORMAT(createtime,'%Y-%m-%d') as Daytime)

from `actors` WHERE ( (`createtime` >= '2019-02-01 00:00:00') AND (`createtime` <= '2019-02-11 24:00:00') )

) a

left join (select * from `actors`

WHERE ( (`createtime` >= '2019-02-01 00:00:00') AND (`createtime` <= '2019-02-11 24:00:00') )

)b

on a.Daytime>=b.createtime

group by a.Daytime

order by 1

SELECT SUM(field_name) FROM tblName WHERE UNIX_TIMESTAMP(month) <= DATE_ADD(CURRENT_DATE(),INTERVAL -1 MONTH) GROUP BY month


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/8545806.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-17
下一篇 2023-04-17

发表评论

登录后才能评论

评论列表(0条)

保存