Не следует смешивать типы данных, как это. Используя следующий тестовый случай:
-- drop table input_table;
create table input_table(
name varchar2(20) not null
,step varchar2(10) not null
,step_date varchar2(10)
);
insert into input_table(name, step, step_date) values('VINOD', 'A', '28.12.013');
insert into input_table(name, step, step_date) values('VINOD', 'B', '11.10.2013');
insert into input_table(name, step, step_date) values('VINOD', 'C', null);
commit;
Следующая (ужасный) запрос должен делать то, что вы просите:
select name
-- If a row exists (has flag) pick whatever value was there, otherwise set NA
,case when max(a_flag) = 'A' then max(a_date) else 'NA' end as a_date
,case when max(b_flag) = 'B' then max(b_date) else 'NA' end as b_date
,case when max(c_flag) = 'C' then max(c_date) else 'NA' end as c_date
,case when max(d_flag) = 'D' then max(d_date) else 'NA' end as d_date
,case when max(e_flag) = 'E' then max(e_date) else 'NA' end as e_date
from (select name
-- Pivot the dates to columns
,case when step = 'A' then step_date end as a_date
,case when step = 'B' then step_date end as b_date
,case when step = 'C' then step_date end as c_date
,case when step = 'D' then step_date end as d_date
,case when step = 'E' then step_date end as e_date
-- Create flags because we have two kinds of NULL...
,case when step = 'A' then 'A' end as a_flag
,case when step = 'B' then 'B' end as b_flag
,case when step = 'C' then 'C' end as c_flag
,case when step = 'D' then 'D' end as d_flag
,case when step = 'E' then 'E' end as e_flag
from input_table
)
group
by name;
ли ваши домашние? –
нет ... это часть моей работы. Поскольку значения чувствительны к компании, я привел пример simiklar к исходным значениям –
okok, это показалось моей типичной проблеме с БД; ;-) –