分组后合并成员
【问题】
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 脚本】