当遇到一些不方便直接用BI主题表实现的分析需求时,通常会考虑用sql数据源来做表。以下简单总结了一些常用的sql数据源的写法,欢迎大家补充~
1. 单级维,可多选,不做选择时缺省过滤
<#=if(@cs="","1=1","standard in ("+replaceregex(@cs,"|",",", true)+")") #>
注:因为“|”这个符号在代码里面是有特定含义的,所以需要用转译一下。
2. 单级维或者枚举下拉时
多选过滤时生成的sql是 in (110000,120000) ,怎样转换成 in("110000","120000") ?
<#=if(@cs="","1=1"," xzqh in ("" + replaceregex(@cs,"|","","") + "")")#>
注:蓝色字体部分是拼接进去的字符串,由于嵌套使用单引号,所以内层的单引号前面加转译一下。
3. 多级维,可多选,分组节点以及叶子节点都允许选择,不做选择时缺省过滤
<#=if(@cs="","1=1","(" + ([] + @cs.value).select(true,
if(@.level=0, "xzqh like "" + left(@,2) + "%"", if(@.level=1, "xzqh like "" + left(@,4) + "%"", "xzqh="" + @ + """))
).join(" or ") + ")")#>
4. 通用维过滤,可多选,不做选择时缺省过滤
select sum(a.DXDBSL) as B1,a.WLCCID as A1,max(b.WLCCMC) as mc_A10
from MQT_CW_GL_DXSLYJZ a
,MQT_DIM_WLCC b
where (A.WLCCID=B.WLCCID(+)) and
<#=if(@hhxx<>"", "(" +(@hhxx+"").split("|").select(true,"a.pp||"$"||a.dl||"$" ||a.xl like ""+@+"%"").join(" or ")+")","1=1") #>
group by a.WLCCID
5. sql数据源分页方法
5.1 Step1
添加一新的sql数据源,命名必须为"totalcount",该sql数据源内容为:
Select count(*) from (原sql)
例如:
sql数据源1:命名为rs1(此处命名可随意定义), sql内容为:
select sum(a.ZSR) as B1,sum(a.ZZC) as C1,a.XZQH as A1,max(b.NAME) as mc_A10
from FACT_SRZC_NEW a
,DIM_WSXZQH b
where (A.XZQH=B.ID(+))
group by a.XZQH
sql数据源2:命名为totalcount(必须为此名),sql内容为:
select count(* ) from (select sum(a.ZSR) as B1,sum(a.ZZC) as C1,a.XZQH as A1,max(b.NAME) as mc_A10
from FACT_SRZC_NEW a
,DIM_WSXZQH b
where (A.XZQH=B.ID(+))
group by a.XZQH)
5.2 Step2
分析区表格设置分页行数
6.温馨提示
使用sql数据源做表时,所有的过滤都需要写到sql中去,报表模板上的过滤条件设置以及报表期设置不生效;
以上四种场景所有写法用例在使用时要注意把参数名、数据库表名、字段名换成自己实际使用场景的名称哟~
请先登录