Coalescing values in a column over a partition

前端 未结 3 1759
悲哀的现实
悲哀的现实 2021-01-06 18:45

I have chosen to ask this question via an example as I think it most clearly illustrates what I am trying to do.

Say I have the following table:

mem         


        
3条回答
  •  长情又很酷
    2021-01-06 19:13

    I know it's bad form answering your own question but I have found this useful page:

    https://www.ibm.com/developerworks/mydeveloperworks/blogs/SQLTips4DB2LUW/entry/aggregating_strings42?lang=en

    Modifying the code there gives:

    create table test (member int, number int, time_stamp time)`;
    
    insert into test values 
    (1,2,'19:21'),
    (1,4,'19:24'),
    (1,27,'19:37'),
    (2,4,'19:01'),
    (2,7,'21:56'),
    (2,8,'22:00'),
    (2,21,'22:01');
    
    select 
      member, substr(xmlcast(xmlgroup('.' || number as a order by time_stamp) as varchar(60)), 2)
    from test
    group by member
    

提交回复
热议问题