当前位置:网站首页>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")
边栏推荐
- c# 怎样能写个sql的解析器
- pyqt5界面的布局与资源文件的载入
- 黑马笔记---包装类,正则表达式,Arrays类
- Flinksql customizes udatf to implement topn
- Android development interview real question advanced version (with answer analysis)
- JMeter之性能测试流程及性能测试关注点
- Commands for redis basic operations
- 7 lightweight and easy-to-use tools to relieve pressure and improve efficiency for developers, and help enterprises' agile cloud launch | wonderful review of techo day
- Shell基础入门
- Docker安装Mysql8和sqlyong连接报错2058的解决方法[随笔记录]
猜你喜欢
Redis-缓存问题
【MySQL】MySQL的安装与配置
[QNX Hypervisor 2.2用户手册]6.2.3 Guest与外部之间通信
Visual Studio配置Qt并通过NSIS实现项目打包
MySQL built-in functions
【C】深入理解指针、回调函数(介绍模拟qsort)
[surprised] the download speed of Xunlei is not as fast as that of the virtual machine
Wechat launched the picture big bang function; Apple's self-developed 5g chip may have failed; Microsoft solves the bug that causes edge to stop responding | geek headlines
黑马笔记---集合(Collection的常用方法与遍历方式)
【 surprise】 la vitesse de téléchargement de Thunderbolt n'est pas aussi rapide que celle de la machine virtuelle
随机推荐
Substrate 源码追新导读: Call调用索引化, 存储层事物化全面完成
【OpenGL】OpenGL Examples
21. Notes on WPF binding
c# 怎样能写个sql的解析器
Sqlserver query code is 936 simplified Chinese GBK. Should I write 936 or GBK?
[one day learning awk] array usage
[surprised] the download speed of Xunlei is not as fast as that of the virtual machine
力扣之螺旋矩阵,一起旋转起来(都能看懂)
Redis configuration files and new data types
grep匹配查找
黑马笔记---集合(Collection的常用方法与遍历方式)
zabbix-server启动失败处理方式
The realization of QT the flipping effect of QQ weather forecast window
Spatiotemporal prediction 2-gcn_ LSTM
pyqt5界面的布局与资源文件的载入
腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
Substrate 源码追新导读: Pallet Alliance 并入主线,
The format of RTSP address of each manufacturer is as follows:
7 lightweight and easy-to-use tools to relieve pressure and improve efficiency for developers, and help enterprises' agile cloud launch | wonderful review of techo day
[QNX Hypervisor 2.2用户手册]6.2.3 Guest与外部之间通信