Здравствуйте, ika, Вы писали:
ika>Можно ли составить изначально такой SQL запрос, чтобы null значения заменялись non-null значениями из следующей записи?
ika>В итоге нужно получить всего одну запись, которая была бы максимально заполнена non-null значениями.
Идея простая. Вот для MS SQL —
create table #t
(
dt integer not null primary key,
c1 integer,
c2 integer,
c3 integer,
c4 integer
);
insert into #t values (1, null, null, null, null);
insert into #t values (2, 1, null, null, null);
insert into #t values (3, null, 2, null, null);
insert into #t values (4, 11, 22, 3, null);
select
c1 = (select top 1 c1 from #t where c1 is not null order by dt),
c2 = (select top 1 c2 from #t where c2 is not null order by dt),
c3 = (select top 1 c3 from #t where c3 is not null order by dt),
c4 = (select top 1 c4 from #t where c4 is not null order by dt)
drop table #t;
Для других серверов будет чуть другой ситаксис, но та же идея.
Подойдет?
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>