Tema: Re: SQL
Autorius: Jornada Del Muerto
Data: 2010-04-16 09:20:00
Siaip tai but nieko koki saituka sumest ir kolekcionuoti tokias "genialias" sistemu architekturas :) but humoro saitas programmeriam :)

Cia aisku NO OFFENCE  NicMC, jis tik kazkieno kakas taiso :)

"2x50" <a@a.a> wrote in message news:hq7sjd$vcf$1@trimpas.omnitel.net...
> ...arba sitaip :)
> 
> with dummy_tbl as
> (
> select to_date('20100103', 'yyyymmdd') stamp from dual union all
> select to_date('20100104', 'yyyymmdd') from dual union all
> select to_date('20100105', 'yyyymmdd') from dual union all
> select to_date('20100120', 'yyyymmdd') from dual union all
> select to_date('20100121', 'yyyymmdd') from dual union all
> select to_date('20100122', 'yyyymmdd') from dual union all
> select to_date('20100123', 'yyyymmdd') from dual union all
> select to_date('20100201', 'yyyymmdd') from dual union all
> select to_date('20100202', 'yyyymmdd') from dual
> )
> 
> select
> group_id,
> q2.stamp,
> first_value (q2.stamp) over (partition by q2.group_id order by q2.stamp) 
> start_date,
> first_value (q2.stamp) over (partition by q2.group_id order by q2.stamp 
> desc) end_date
> from
> (
> select
>  q1.stamp,
>  sum (q1.start_of_group) over (order by q1.stamp) group_id
> from
> (
> select
>  t.stamp,
>  lag (t.stamp, 1, t.stamp) over (order by t.stamp) pre_stamp,
>  t.stamp - lag (t.stamp, 1, t.stamp-11) over (order by t.stamp) stamp_diff,
>  case when t.stamp - lag (t.stamp, 1, t.stamp-11) over (order by t.stamp) > 
> 1 then 1 end start_of_group
> from dummy_tbl t
> ) q1
> ) q2 
> 
>