我有一个包含列的表:
date_report entity value code_column
12/02/2014 10 0.5 1
12/02/2014 10 333 2
12/02/2014 10 -44 3
12/02/2014 11 0.3 1
12/02/2014 14 0.5 1
12/02/2014 11 777 2
12/02/2014 14 -4 3
12/03/2015 10 0.4 1
12/03/2015 15 432 2
10/01/2014 12 555 2
我希望将行转换为列,当" date_report"和"实体"就像一个键(它们仍然存在),code_column转换为新列的名称,值是新列中的值。 像:
date_report entity A B C
12/02/2014 10 0.5 333 -44
12/02/2014 11 0.3 777
12/02/2014 14 0.5 -4
12/03/2015 10 0.4
12/03/2015 15 432
10/01/2014 12 555
答案 0 :(得分:1)
您可以使用条件聚合:
<WixVariable Id="WixUIDialogBmp" Value="Images\d.bmp" />
答案 1 :(得分:1)
您可以尝试这样:
WITH TB_TAM AS(
SELECT '12/02/2014' date_report, 10 entity, 0.5 valueT, 1 code_column FROM DUAL UNION ALL
SELECT '12/02/2014' date_report , 10 entity, 333 valueT, 2 code_column FROM DUAL UNION ALL
SELECT '12/02/2014' date_report , 10 entity, -44 valueT, 3 code_column FROM DUAL UNION ALL
SELECT '12/02/2014' date_report , 11 entity, 0.3 valueT, 1 code_column FROM DUAL UNION ALL
SELECT '12/02/2014' date_report , 14 entity, 0.5 valueT, 1 code_column FROM DUAL UNION ALL
SELECT '12/02/2014' date_report , 11 entity, 777 valueT, 2 code_column FROM DUAL UNION ALL
SELECT '12/02/2014' date_report , 14 entity, -4 valueT, 3 code_column FROM DUAL UNION ALL
SELECT '12/03/2015' date_report , 10 entity, 0.4 valueT, 1 code_column FROM DUAL UNION ALL
SELECT '12/03/2015' date_report , 15 entity, 432 valueT, 2 code_column FROM DUAL UNION ALL
SELECT '10/01/2014' date_report , 12 entity, 555 valueT, 2 code_column FROM DUAL
)
select * from TB_TAM
PIVOT ( sum(valueT)for code_column in (1 as a,2 as b,3 as c))
order by date_report,entity