0

I am working to try to collect all data belonging to a particular category into a Json structure or set.

for Example

ID Status Dim
A P 5
B Q 10
C R 15
D S 5
A T 6
C U 9
D V 20
E W 100
A X 6
F Y 69

Output should be:

ID Collect Max Instances
A {P:5,T:6,X:6} 6 3
B {Q:10} 10 1
C {R:15,U:9} 15 2
D {S:5,V:20} 20 2
E {W:100} 100 1
F {Y:69} 69 1

I cannot create procedures since the org has not given me the appropriate privilege.

I was looking into multiset in Informix but that is confusing-

I wrote the query to try to build the first two columns, because I can write the max and instances later

    select id,multiset(select status, dim from table i where i.id=t.id) Collect from table t where category='A'

This gave me 3 rows all containing the same value

id collect
A [IfxStruct. Type: row ( item_nbr int not null) , IfxStruct. Type: row ( item_nbr int not null) , IfxStruct. Type: row ( item_nbr int not null) ]
A [IfxStruct. Type: row ( item_nbr int not null) , IfxStruct. Type: row ( item_nbr int not null) , IfxStruct. Type: row ( item_nbr int not null) ]
A [IfxStruct. Type: row ( item_nbr int not null) , IfxStruct. Type: row ( item_nbr int not null) , IfxStruct. Type: row ( item_nbr int not null) ]

I would settle for a comma seperated list of values For example

id collect
A "P:5","T:6","X:6"
  • 1
    You can fiddle a bit with the function GENBSON [(functions-genbson-function)](https://www.ibm.com/docs/en/informix-servers/12.10?topic=functions-genbson-function) but your collect column will need an aggregate function. Which you need to define [(Informix aggregates)](https://stackoverflow.com/questions/715350/show-a-one-to-many-relationship-as-2-columns-1-unique-row-id-comma-separate), but you wrote that you do not have the privileges. You will have to do the aggregation outside Informix. – Luís Marques Jan 10 '23 at 15:08

0 Answers0