当前位置:网站首页>2022-06-23 帆软部分公式及sql生成(月份、季度取数)
2022-06-23 帆软部分公式及sql生成(月份、季度取数)
2022-06-30 12:19:00 【玩猪猪】
以下均为帆软公式:
1.获得当前月往后推三月,如当前为8月,获得“9-11月”字样
if($DATA_MONTH_BOX<10,($DATA_MONTH_BOX+1)+'-'+($DATA_MONTH_BOX+3)+'月',
if($DATA_MONTH_BOX=10,$DATA_YEAR_BOX+'年11月-'+$NEXT_YEAR+'年1月',
if($DATA_MONTH_BOX=11,$DATA_YEAR_BOX+'年12月-'+$NEXT_YEAR+'年2月',
if($DATA_MONTH_BOX=12,$NEXT_YEAR+'年1-3月',''))))
获得后一月,如当前8月,获得"9月",当前为12月,获得“+1年1月”
IF($DATA_MONTH_BOX<12,($DATA_MONTH_BOX+1)+'月',
if($DATA_MONTH_BOX=12,$NEXT_YEAR+'年1月',''))
获得后两月
IF($DATA_MONTH_BOX<11,($DATA_MONTH_BOX+2)+'月',
if($DATA_MONTH_BOX=11,$NEXT_YEAR+'年1月',
IF($DATA_MONTH_BOX=12,$NEXT_YEAR+'年2月','')))
获得后三月
IF($DATA_MONTH_BOX<10,($DATA_MONTH_BOX+3)+'月',
if($DATA_MONTH_BOX=10,$NEXT_YEAR+'年1月',
IF($DATA_MONTH_BOX=11,$NEXT_YEAR+'年2月',
IF($DATA_MONTH_BOX=12,$NEXT_YEAR+'年3月',''))))
2.获得1-上月份,当前月为1月时,获得“去年1-12月”
if($月份 != 1 && $月份 != 2, $月份 + '月占比比1-' + ($月份 - 1) + '月', if($月份 = 1, $月份 + '月占比比去年1-12月', '2月占比比1月'))
sql语句示例:
sum(case when t.data_year='${去年}' and t.data_month='${月份}' then t.num else 0 end ) as 厂家同期当月,
${
if(月份=='2',"sum(case when t.data_year='"+年度+"' and t.data_month='1' then t.num else 0 end ) as 厂家1至上月累计,","")}
${
if(月份=='1',"sum(case when t.data_year='"+去年+"' then t.num else 0 end ) as 厂家1至上月累计,","")}
${
if(月份!='1' && 月份!='2',"sum(case when t.data_year='"+年度+"' and t.data_month<="+(月份-1)+" then t.num else 0 end ) as 厂家1至上月累计,","")}
3.获得当前季度
if($月份 % 3 = 0, $月份 / 3, Int($月份 / 3) + 1) + '季度'
sql语句示例:
设置控件为${当季度_s}=if($月份 % 3 = 0, $月份 / 3, Int($月份 / 3) + 1)
sum(case when t.data_year='${年度}' and (t.data_month>=(1+3*(${当季度_s}-1)) and t.data_month<=(${当季度_s}*3)) then t.num else 0 end ) as 厂家季度销量,
当数据类型为t.yue1这种时
JOINARRAY(RANGE(if($月份%3=0,$月份/3-1,Int($月份/3))*3+1,if($月份%3=0,$月份/3-1,Int($月份/3))*3+3,1),"+t.yue")
4.获得1-当前季度
'1-' + if($月份 % 3 = 0, $月份 / 3, Int($月份 / 3) + 1) + '季度'
sql语句示例:
sum(case when t.data_year='${年度}' and t.data_month<=(${当季度_s}*3) then t.num else 0 end ) as 厂家季度累计,
sum(case when t.data_year='${去年}' and t.data_month<=(${当季度_s}*3) then t.num else 0 end ) as 厂家同期季度累计,
5.获得1-上季度,当前季度为1时,获得“去年1-4季度”,此处示例为“当季度占比比1-上季度”
if(if($月份 % 3 = 0, $月份 / 3, Int($月份 / 3) + 1)!='1',if($月份 % 3 = 0, $月份 / 3, Int($月份 / 3) + 1) + '季度占比比1-' + (if($月份 % 3 = 0, $月份 / 3, Int($月份 / 3) + 1) - 1) + '季','1季度占比比去年1-4季度')
sql语句示例:
${
if(当季度_s!='1',
"sum(case when t.data_year='"+年度+"' and (t.data_month>=1 and t.data_month<="+((当季度_s-1)*3)+") then t.num else 0 end ) as 厂家1至上季度累计,",
"sum(case when t.data_year='"+去年+"' then t.num else 0 end ) as 厂家1至上季度累计,")}
当数据库一年数据放在一条内时:
IF(
if($月份 % 3 = 0, $月份 / 3, Int($月份 / 3) + 1)!='1',
JOINARRAY(
RANGE(
(if($月份%3=0,$月份/3-1,Int($月份/3))-1)*3+1,
(if($月份%3=0,$月份/3-1,Int($月份/3))-1)*3+3,
1
)
,"+t.yue"
),
'10+t.yue11+t.yue12'
)
6.获得当季度,如当前3月,获得“1季度”
if($月份%3=0,$月份/3,Int($月份/3)+1)
sql语句示例:
获得季度累计的月份计算sql,如当前月为4月,获得1-2季度即1-6月的月份累计sql
sum(case when t.data_year='${年度}' and (t.data_month>=(1+3*(${当季度_s}-1)) and t.data_month<=(${当季度_s}*3)) then t.num else 0 end ) as 厂家季度销量,
如果是一年的销量数据放在一条数据内:
JOINARRAY(RANGE(1,if($月份%3=0,$月份/3-1,Int($月份/3))*3+3,1),"+t.yue")
边栏推荐
- Tencent cloud Database Engineer competency certification was launched, and people from all walks of life talked about talent training problems
- Three ways for flinksql to customize udaf
- 【一天学awk】正则匹配
- 【惊了】迅雷下载速度竟然比不上虚拟机中的下载速度
- Why should offline stores do new retail?
- Redis-缓存问题
- Qt中的数据库使用
- Flink SQL console, group not recognized_ Concat function?
- [surprised] the download speed of Xunlei is not as fast as that of the virtual machine
- Scratch drawing square electronic society graphical programming scratch grade examination level 2 true questions and answers analysis June 2022
猜你喜欢

【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(二)

黑马笔记---List系列集合与泛型

21. Notes on WPF binding

Basic interview questions for Software Test Engineers (required for fresh students and test dishes) the most basic interview questions

Unity脚本的基础语法(1)-游戏对象的常用操作

Efficient elliptic curve point addition and multiplication in scrypt

QT MSVC installation and commissioning

电机控制Clarke(α/β)等幅值变换推导

如何利用AI技术优化独立站客服系统?听听专家怎么说!

Shell基础入门
随机推荐
How to use the plug-in mechanism to gracefully encapsulate your request hook
黑马笔记---常用日期API
浅谈 JMeter 运行原理
elementui中清除tinymce富文本缓存
论文解读(AGC)《Attributed Graph Clustering via Adaptive Graph Convolution》
QT MSVC installation and commissioning
MySQL built-in functions
[qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external
Tencent cloud Database Engineer competency certification was launched, and people from all walks of life talked about talent training problems
SQLSERVER 查询编码是 936 简体中文GBK,那我是写936 还是写GBK?
kubeedge的核心理念
[surprised] the download speed of Xunlei is not as fast as that of the virtual machine
Substrate 源码追新导读: 质押额度大幅度削减, RocksDB可以完全被Disable
90. (cesium chapter) cesium high level listening events
Questionnaire star questionnaire packet capturing analysis
FFMpeg AVBufferPool 的理解与掌握
江西财经大学智慧江财登录分析
电机控制Clarke(α/β)等幅值变换推导
电机控制park变换公式推导
pyqt5界面的布局与资源文件的载入