Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

help me to group the records - response (8) by tusharraste

$
0
0

Hi Gowtham,
I tried the following at it seems to be working, please check and let me know :

create volatile table brain_twister
(
id integer,
id_type char(1),
stdt date,
endt date
)
primary index (id)
on commit preserve rows;

insert into brain_twister values(1,'A',1130801,1130810);
insert into brain_twister values(1,'A',1130811,1130820);
insert into brain_twister values(2,'B',1130821,1130830);
insert into brain_twister values(2,'B',1130831,1130909);
insert into brain_twister values(1,'A',1130910,1130920);
insert into brain_twister values(1,'A',1130821,1130830);
insert into brain_twister values(1,'A',1130921,1130930);

sel distinct id, id_type, min_stdt,max_endt from
(sel
id,
id_type,
stdt,
endt,
max(endt) over(partition by id,id_type order by stdt,endt reset when stdt -1 > max(endt) over(partition by id,id_type order by stdt, endt rows between unbounded preceding and 1 preceding)) max_endt
,min(stdt) over (partition by id,id_type order by stdt,endt reset when stdt -1 > max(endt) over(partition by id,id_type order by stdt, endt rows between unbounded preceding and 1 preceding)) min_stdt
from brain_twister
) temp


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>