多行到一行

时间:2014-11-01 08:29:37

标签: sql database oracle

我在oracle中有一个结果集如下:让表名为t1

Name    | phase|   a_plan  | a_actual | b_plan   | b_actual  |  c_plan  | c_actual
===================================================================================
RKM     | m5-m6|   1/1/2014|1/6/2014  | 2/2/2014 |           |  3/3/2014|
RKM     | m5-m6|   1/1/2014|          | 2/2/2014 | 4/2/2014  |  3/3/2014|
RKM     | m5-m6|   1/1/2014|          | 2/2/2014 |           |  3/3/2014| 5/3/2014

虽然我需要将结果集放在一行中:( a-Plan,b_plan,c_plan在所有3行中相同,但每行只有实际列chnages)

Name    | phase|   a_plan  | a_actual | b_plan   | b_actual  |  c_plan  | c_actual
===================================================================================
RKM     | m5-m6|   1/1/2014|1/6/2014  | 2/2/2014 | 4/2/2014  |  3/3/2014| 5/3/2014

帮助构建查询?

1 个答案:

答案 0 :(得分:0)

SELECT NAME, 
       phase, 
       a_plan, 
       Max(a_actual), 
       b_plan, 
       Max(b_actual), 
       c_plan, 
       Max(c_actual) 
FROM   table 
GROUP  BY NAME, 
          phase, 
          a_plan, 
          b_plan, 
          c_plan
/