当前位置:网站首页>月环比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;

边栏推荐
- ⼤⼚⾯试真题集合
- Michael Wooldridge, professeur à l'Université d'Oxford: comment la communauté de l'IA voit les réseaux neuronaux depuis près de 40 ans
- Understanding of closures
- Opengauss kernel: analysis of SQL parsing process
- 解析机器人主持教学的实践发展
- 获取当前日期0点及23点59时间戳
- About Significance Tests
- leetcode 1689. Partitioning Into Minimum Number Of Deci-Binary Numbers(最少的“二进制数“个数)
- Professor Michael Wooldridge of Oxford University: how the AI community views neural networks in the past 40 years
- PostgreSQL database docker
猜你喜欢

Analysis of the core components of mybayis

Voice network VQA: make the user's subjective experience of unknown video quality in real-time interaction known

模块化操作

Lumiprobe非荧光叠丨氮化物研究丨3-叠丨氮丙醇

Memory leak

About Significance Tests

618 activity season - the arrival of special discounts for hundreds of low code platforms

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 容器分类、array、vector容器精解

业务层修改--根据现有框架的反推修改
随机推荐
基于管线的混合渲染
好用、强大的PDF 阅读软件综合评测:PDF Expert 、MarginNote、LiquidText、Notability、GoodNotes、Zotero
About Statistical Distributions
postgresql数据库docker
内存泄露
Anonymous function variable problem
An in-depth analysis of the election mechanism in kubernetes
OOM out of memory 内存溢出
Upload file list (repeated file names are marked with brackets)
idea其他分支合并到dev分支
Mindspire series one loading image classification data set
Openharmony - detailed source code of Kernel Object Events
Taishan Office Technology Lecture: word strange font height
Collection of real test questions
C# 41. Int to string
Shell script batch modify file directory permissions
Pipeline based hybrid rendering
Render function parsing
C语言文件操作
Native implementation Net5.0+ custom log