在ORACLE 11g中填充多个数据元素

时间:2014-08-07 17:40:16

标签: oracle11g

我正在尝试将几个数据元素填充到Oracle 11g中的一个列中,但只是部分成功。 以下是两个样本记录。

IRS_Forms   Tax_Date        Tax_Id  Tax_Times
1040A       5/9/2011 4:51:00 AM BB11    2
1099B       5/9/2011 4:51:00 AM BB11    2

从这里开始,我可以将IRS_Forms列填入下面的脚本:

Select
Tax_Id,
Tax_Date,
LISTAGG(IRS_Forms,', ')  WITHIN GROUP (ORDER BY IRS_Forms) AS TAX_TYPES
from
 (
     IRS_Forms  Tax_Date        Tax_Id  Tax_Times
     1040A  5/9/2011 4:51:00 AM BB11    2
     1099B  5/9/2011 4:51:00 AM BB11    2
  )X
group by Tax_id, Tax_date

输出结果:

Tax_id  Tax_Date                Tax_TYPES
BB11    5/9/2011 4:51:00 AM     1040A, 1099B

是否有人能够协助我将其他数据填入Tax_TYPES,例如在上面的Tax_Times列中添加()中的计数?非常感谢!!! 这是我想要的输出:

Desired result:
Tax_id    Tax_Date            Tax_TYPES
BB11    5/9/2011 4:51:00 AM     1040A (2),1099B (2)

1 个答案:

答案 0 :(得分:1)

听起来你只是想要

LISTAGG(IRS_Forms || ' (' || tax_times || ')',', ')  
  WITHIN GROUP (ORDER BY IRS_Forms) AS TAX_TYPES