如何在oracle中将多行合并为一行?

时间:2017-07-18 11:13:47

标签: sql oracle

您好我在其中一个表中有这样的数据。由于A列对于所有行都是相同的,我需要将“J”列数据合并为单行。你能告诉我如何编写sql查询来实现这个在oracle中吗?

A   B   C   D   E   F   G   H   I     J
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset#6076,Amount: $29.02       
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6077,Amount: $28.9       
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6078,Amount: $50.64      
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6079,Amount: $18.84      
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6080,Amount: $18.84      
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6081,Amount: $18.83      
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6082,Amount: $58.65      
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6083,Amount: $13.19      
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6084,Amount: $13.19      
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6085,Amount: $13.19      
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6086,Amount: $240.52     
03494   42934.24784 SPPT    Y   1           Property Tax Assessment 42736   
Asset #6087,Amount: $135.98     

我有以下问题来解决这个问题。但问题是它 花费太多时间来检索。有没有其他方法可以使它工作 快?

select lse_id app_lse_s,
       sysdate dt_ent_s,
       'SPPT' note_type_s,
       'Y' prcs_c,
       '1' prio_c,
       '   ' from_s,
       '   ' to_s,
       'Property Tax Assessment' note_title_s,
       lien_dt info1_s,
       LISTAGG('Asset #' || SG.AST_ID  ||  ',' || 'Amount: $' || 
                SG.ASES_PRT_1_AM , ',')
         WITHIN GROUP (ORDER BY SG.AST_ID,SG.ASES_PRT_1_AM) info2_s
from   nmac_ptms_notebk_sg SG
where  lse_id = '     03494'
group by lse_id,
         lien_dt;  

0 个答案:

没有答案