列转行

【问题】

I have a long report which shows a lot of KPIs with columns for today, yesterday, last month, year to date etc.

Each is a sub report which returns one row with all the required KPIs for the given period, e.g,

registrationsdepositsgames
3123

There are about 30 of these KPIs (i.e. 30 column headers in the sub reports)

The report will look like this:

 kpitodayyesterdaythis monthlast monththis year
registrations341942333
deposits111213111
games2324292223
etc

The problem is In the sub report.  i have to explicitly create a field for each KPI, then explicitly create a text box going down the page for each field.

Is there no way to simply list the data which comes back from the query going down the page?  I know there is a table component, but this only works if you ahve a single query which returns multiple rows, I have mutliple queries whcih return a single row each.

【回答】

这张报表之所以复杂,是因为源数据不符合报表要求。按照要求的业务逻辑,可以将不同的“one row with all the required KPIs”在 SQL 中 union 成如下格式:

rangeregistrationsdepositsgames
today3123
yesterday4124
thisMonth191229
lastMonth421322
thisYear33311123

将上面的数据转置后再呈现,难度就会大幅降低。使用 SPL 可以辅助 Jasper 转置任意结构的 SQL 结果集,代码如下:

AB
1=myDB1.query("select * from   KPISubtoal")
2=A1.fname().to(2,)
3=create(KPI).record(A2)
4for A1=columnName=A4.#1
5=A4.array().to(2,)
6=A3=eval("A3.derive(B5(#):"+columnName+")")

A1:执行 SQL 取数

A2:取 A1 结果集中的列名称,从第 2 个开始返回,结果如下:

A3:创建序表

A4-B6:循环 A1,将对应值写入 A3 结果序表中

Jasper 可以通过 JDBC 连接集算器,调用脚本方法和调用存储过程一样,详情参考【JasperReport 调用 SPL 脚本】。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值