【问题】
I am new to jasper. I am having a problem to design a report which does the same like group_concat() function in my sql.. i am using a sql server so cannot use that function in my query.
My input is something like this.
Col1 Col2 Col3 Col4 10 1234 Sam A12G3 10 1234 Sam K78DE 10 1234 Sam MAT12 20 1456 Tom E12F4 20 1456 Tom KAR3R 20 3217 Tom G45G4
my output should be like
Col1 Col2 Col3 Col4 10 1234 Sam A12G3 , K78DE , MAT12 20 1456 Tom E12F4 , KAR3R 20 3217 Tom G45G4
I am trying to create a variable using the below expression.
Class : java.lang.String , CALCULATION: Nothing , Incrementype: Group , Incrementgroup: Col2
expression is $F{Col4} + "," + $F{Col4}
this one is not working.. Could you please help me on this please
【回答】
SQL 和 Jasper 应该都能实现 group_concat 函数,只是代码比较难写。可以试试用 SPL 来辅助 Jasper。
如下代码就能实现与 group_concat 等价的功能,而且与数据库无关:
| A | |
| 1 | =mySqlDB.query("select * from table1"). group(Col1,Col2,Col3;~.(Col4).concat@c():Col4) |
集算器提供 JDBC 接口与 Jasper 集成,与数据库的用法相同,详情参考【JasperReport 调用 SPL 脚本】
在Jasper报表中实现分组合并
在Jasper报表设计中,遇到无法使用SQL的group_concat()函数问题。目标是将同一组的Col4字段值用逗号连接。尝试创建变量用表达式$F{Col4} + "," + $F{Col4},但未成功。解决方案是借助SPL脚本,它能提供与group_concat类似的功能,并且与数据库无关,通过JDBC接口与Jasper集成。"
97233457,8340833,SQL数据更新操作详解,"['数据库管理', 'SQL语言', '数据操作']
687

被折叠的 条评论
为什么被折叠?



