当前位置:网站首页>月环比sql实现
月环比sql实现
2022-06-28 18:39:00 【南湖渔歌】
##月环比
with temp as(
-- 对fct_sales的数据按照日期进行聚合
select dimDateID
,round(SUM(AMT),0) AS AMT
from dw.fct_sales
WHERE dimMemberID <> 0
group by dimDateID
)
select substr(a.d,1,7) as 'month'
,STR_TO_DATE(a.d,'%Y-%m-%d') as time
,a.AMT
,b.dd
,b.originalday
,b.AMT as AMT_last
,(a.AMT-b.AMT)/b.AMT as month_rate
from
(select DATE_FORMAT(dimDateID,'%Y-%m-%d') as d
,AMT
from temp
) a
left join
(select DATE_ADD(DATE_FORMAT(dimDateID,'%Y-%m-%d'),INTERVAL 1 month ) as dd
,DATE_FORMAT(dimDateID,'%Y-%m-%d')as originalday
,AMT
from temp
) b
on a.d=b.dd;

边栏推荐
- id门禁卡复制到手机_怎么把手机变成门禁卡 手机NFC复制门禁卡图文教程
- 福建的朋友们,你们的养老保险上云啦!
- FFmpeg学习总结
- Yixin Huachen: real estate enterprises want to grasp the opportunity of the times for digital transformation
- Voice network VQA: make the user's subjective experience of unknown video quality in real-time interaction known
- First day of new work
- About Significance Tests
- Analysis of the core components of mybayis
- Analyzing the practical development of robot teaching
- Enhancing steam and engineering education from theory to practice
猜你喜欢

Mybayis之核心主件分析

Michael Wooldridge, professeur à l'Université d'Oxford: comment la communauté de l'IA voit les réseaux neuronaux depuis près de 40 ans

Memory leak

Opengauss kernel: analysis of SQL parsing process

推荐两款超高质量的壁纸软件

MindSpore系列一加载图像分类数据集

1 invalid import format(s) Postman Collection Format v1 is no longer supported and can not be import

618活动季——百数低代码平台特享折扣来临

毕业设计-基于Unity的餐厅经营游戏的设计与开发(附源码、开题报告、论文、答辩PPT、演示视频,带数据库)

模块化操作
随机推荐
解析机器人主持教学的实践发展
Summary of the use of qobjectcleanuphandler in QT
618 activity season - the arrival of special discounts for hundreds of low code platforms
Understanding of closures
[unity3d] emission (raycast) physical ray (Ray)
应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)
leetcode 1647. Minimum Deletions to Make Character Frequencies Unique(所有字母频率不同的最小删除次数)
Business layer modification - reverse modification based on the existing framework
Oom out of memory memory overflow
Enhancing steam and engineering education from theory to practice
Mybayis之核心主件分析
匿名函数变量问题
curl: (56) Recv failure: Connection reset by peer
About Significance Tests
MindSpore系列一加载图像分类数据集
Michael Wooldridge, professeur à l'Université d'Oxford: comment la communauté de l'IA voit les réseaux neuronaux depuis près de 40 ans
19.2 container classification, array and vector container refinement
An in-depth analysis of the election mechanism in kubernetes
C语言指针的一些易错点
First day of new work