How to hide duplicates values in column

2019-08-18 13:23发布

问题:

I have 2 tables in sql table_a and table_b this is the output: (1 to many relationship)

table_a                    table_b
id_no (pk)  name            id_no (fk)      id_tabl(pk)     order_code     order_item
1            a                1                 1              11              aple
1            a                1                 2              12              orange
1            a                1                 3              13              ice
2            b                2                 4              12              orange
2            b                2                 5              13              ice
3            c                3                 6              13              ice
3            c                3                 7              12              orange
3            c                3                 8              11              aple

I want to display only 1 name with all his order_item.

How can I display it using iReport in the xml?

The output sample:

id_no      name    order_item
1           a       aple
                    orange
                    ice
2           b       orange
                    ice
3            c       ice
                    orange
                    aple

Using only 2 (order_item) field pattern in every pages of my invoice the other display will be displayed in invoice pages 2.

回答1:

You should use Data Grouping.

You can read this article about data grouping.

  • Your can use the query like this:
SELECT table_a.id_no, table_a.name, table_b.order_item FROM table_a, table_b WHERE table_a.id_no=table_b.id_no ORDER BY table_a.name

Note: may be you need to add sort by table_a.id_no column.

  • You should create the iReport's group for the name field

Note: may be you need to create two groups - for id_no and name fields.

  • You can use the Group and Details bands for drawing the data row. Or you can put all textField elements to the Detail band. In this case you should set false value to the isPrintRepeatedValues textField's property (for id_no and name fields).