Mysql写近一年每个月的统计 案例 SQL: -- 外层sql求同月不同情况的总和SELECT sum(one + two+three+four+ five+six+seven+eight)
案例
SQL:
-- 外层sql求同月不同情况的总和SELECT sum(one + two+three+four+ five+six+seven+eight) as total ,createDate as month FROM (-- 按月份获取每月不同情况的数据SELECT sum(gift = 0.38) one ,sum(gift = 0.58) two,sum( gift = 0.68 ) three ,sum(gift =0.88) four, sum(gift = 38) five,sum(gift = 5) six,sum(gift = 10) seven ,sum(gift = 0) eight,DATE_FORMAT(create_time, '%Y-%m' ) as createDateFROM game-- 按时间月份分组group by createDate -- 按月份倒序取前12条,实现取近12个月的数据order by createDate desc limit 12 ) as A group by createDate
效果:
来源地址:https://blog.csdn.net/Do_LaLi/article/details/129497371
--结束END--
本文标题: 如何用SQL实现近12个月不同情况数量总和的数据统计?
本文链接: https://www.lsjlt.com/news/386256.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
2024-05-03
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0