子表分栏

【问题】
Hello people:

i have  this data:    {AAA , 18} ,{BBB, 10} , {CCC ,20},{DDD, 65}, …….. {SSS, 16}.
i want to show it in the report like that:

AAA    18     DDD  65    GGG 33    ………. SSS   16
BBB   10     EEE   13    …
CCC  20     FFF    98    …

Any idea? , i am using a normal table, but all the data is under , Example : 

AAA    18

BBB   10

CCC  20

….

but the thing is that i have several bands, some tables, but just 1 is like the example i showed you,   then i was thinking in use a subreport, what do you think?

【回答】
假设源数据是 10 条双字段的记录,分栏数 colN=3,则需要生成一个 6 字段的二维表。可用 SPL 整理数据,代码较简单:

A
1 =connect(“demo”) 
2 =A1.query(“SELECT name,value FROM tb”)
3 =ceil(A2.len()/colN)
4 =A2.group(ceil(#/A3))
5 =create(${colN.(“name”/ ~ /“,value”/ ~).concat@c()}))
6 =A5.paste(${A4.len().($[A4(]/ ~ /$[).(#1),A4(]/ ~ /“).(#2)”).concat@c()})

运行结果:

A1:连接数据库

A2:查找数据

A3:计算分栏后的行数

A4:分组计算

A5:创建 name 和 value 为字段的空序表

A6:按照字段顺序,依次修改序表中的记录