当前位置:网站首页>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")
边栏推荐
- 21. Notes on WPF binding
- Mysql判断计算结果,除以100
- Substrate 源码追新导读: 波卡系波卡权重计算全面更新, Governance 2.0 版本的优化和调整
- 基于ThinkPHP5封装tronapi-波场接口-PHP版本--附接口文档-20220627
- Redis configuration files and new data types
- Dqn notes
- Spatiotemporal prediction 2-gcn_ LSTM
- Redis - problèmes de cache
- Android development interview real question advanced version (with answer analysis)
- Substrate 源码追新导读: 5月中旬: Uniques NFT模块和Nomination Pool
猜你喜欢
随机推荐
Qt中的事件处理
Swagger2 automatically generates API documents
Redis-缓存问题
SuperMap 3D SDKs_ Unity plug-in development - connect data services for SQL queries
Spatiotemporal prediction 2-gcn_ LSTM
Substrate 源码追新导读: Pallet Alliance 并入主线,
MySQL built-in functions
Mysql中 begin..end使用遇到的坑
时空预测2-GCN_LSTM
[one day learning awk] Fundamentals
Introduction to the novelty of substrat source code: indexing of call calls and fully completing the materialization of storage layer
“\“id\“ contains an invalid value“
Unity脚本程序的开发
市值蒸发650亿后,“口罩大王”稳健医疗,盯上了安全套
60 divine vs Code plug-ins!!
Substrate 源码追新导读: 波卡系波卡权重计算全面更新, Governance 2.0 版本的优化和调整
黑马笔记---常用日期API
Flink SQL console, group not recognized_ Concat function?
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
Reading the table data of Tencent documents in the applet









