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

边栏推荐
- leetcode 1423. Maximum Points You Can Obtain from Cards(从牌中能得到的最大点数和)
- 19.2 容器分类、array、vector容器精解
- Advanced technology management - how managers communicate performance and control risks
- About Statistical Distributions
- 声网发布灵隼物联网云平台 可一小时构建示例场景
- C# 41. int与string互转
- PostgreSQL database docker
- 180.1.连续登录N天(数据库)
- 从理论到实践增强STEAM和工程教育
- leetcode 1689. Partitioning Into Minimum Number Of Deci-Binary Numbers(最少的“二进制数“个数)
猜你喜欢
随机推荐
Yixin Huachen: real estate enterprises want to grasp the opportunity of the times for digital transformation
3D rotatable particle matrix
获取当前日期0点及23点59时间戳
1 goal, 3 fields, 6 factors and 9 links of digital transformation
sqrt()函数的详解和用法「建议收藏」
Can I open an account today and buy shares today? Is it safe to open an account online?
[unity3d] emission (raycast) physical ray (Ray)
声网发布灵隼物联网云平台 可一小时构建示例场景
安装nodejs环境
async-validator.js数据校验器
进阶高级-业务事务设计 开发入门
An in-depth analysis of the election mechanism in kubernetes
Voice network VQA: make the user's subjective experience of unknown video quality in real-time interaction known
C# 41. Int to string
从知名软件提取出的神器,吊打一众付费
抗兔Dylight 488丨Abbkine通用型免疫荧光(IF)工具箱
Cannot read property 'MTJ' of undefined
【Unity3D】发射(RayCast)物理射线(Ray)
180.1. Log in continuously for n days (database)
双功能交联剂丨Lumiprobe 磺基花青7二羧酸研究









