oracle11g - How to create a concatenated column if your are getting data from a single column? -
i have column called issue_status column, presents current status of issue raised related in risk management. need to create new column in both cognos and/or sql server present concatenated columns of previous statuses of issue. goes this.
right now, don't have issue_status_concatenated.
it goes this.
issue i.d issue status 1234 draft 1234 open 1234 closed 5678 draft 5678 pending 5678 closed 5678 cancelled 3333 draft 3333 pending 3333 pending 3333 pending
i thinking of using running count function (cognos function)
issue i.d issue status running_count 1234 draft 1 1234 open 2 1234 closed 3 5678 draft 1 5678 pending 2 5678 closed 3 5678 cancelled 4 3333 draft 1 3333 pending 2 3333 pending 3 3333 pending 4
then combine results inside single column using case function
new concat_column 1 case when running_count = 1 issue_status else ' ' end new concat_column 2 case when running_count = 2 issue_status else ' ' end new concat_column 3 case when running_count = 3 issue_status else ' ' end new concat_column 4 case when running_count = 4 issue_status else ' ' end
then plan create new data item or new column creating issue_status_concatenated combining new concat columns 1
new concat_column 1 + '|' + new concat_column 2 + '|' + new concat_column 3 + '|' + new concat_column 4
i know long process know there easier , logical way this? there way make simpler?
issue i.d issue status issue_status_concatenated 1234 draft draft | open | closed 1234 open draft | open | closed 1234 closed draft | open | closed 5678 draft draft | open | closed |cancelled 5678 pending draft | open | closed |cancelled 5678 closed draft | open | closed |cancelled 5678 cancelled draft | open | closed |cancelled 3333 draft draft | pending 3333 pending draft | pending 3333 pending draft | pending 3333 pending draft | pending
below snippet desird output in oracle. hope helps.
select id, stat, listagg(stat,'|') within group( order stat) over(partition id) agg_stat (with tmp ( select 1234 id, 'draft' stat dual union select 1234 id, 'open' stat dual union select 1234 id, 'completed' stat dual union select 1100 id, 'draft' stat dual union select 1100 id, 'pending' stat dual union select 1100 id, 'completed' stat dual union select 1100 id, 'closed' stat dual ) select tmp.*,row_number() over(partition id order 1 desc) rn tmp );
wiki
Comments
Post a Comment