del greicio nesigincysiu - reikia tvarkyti, bet del rezultato tai klysti (cia tuo atveju kaip minejau jei intervalai gali buti keli ir einantys nenuosekliai) "CGI 600" <nespamink@spamas.lt> wrote in message news:l1nc03$upt$1@trimpas.omnitel.net... > Idomiai cia tu :) bandej su didesniu kiekiu irasu, manau jei tas penkias > eilutes suinsertintum kokius 400 kartu (gautusi 2k irasu), tai tavo > selektas turetu suktis ne trumpiau kaip 1min ir gautum ta pati jei > rasytum: > SELECT [ELEMENT], MIN([START]), MAX([END], [VALUE] > FROM [Table1] > GROUP BY [ELEMENT], [VALUE] > > o pastarasis jei uztruks 2ms tai bus maksimumas. > > > ps. Jei netingi pratestuok, as tingiu, bet esu isitikines 99% kad taip > bus. > > On 2013.09.22 18:44, blah wrote: >> WITH CteTable AS ( >> SELECT [ELEMENT], [START], [END], [VALUE] >> FROM [Test].[dbo].[Table1] t1 >> WHERE NOT EXISTS (SELECT 1 FROM [Test].[dbo].[Table1] t2 >> WHERE t1.[ELEMENT] = t2.[ELEMENT] AND >> t1.[VALUE] = t2.[VALUE] AND DATEADD(DAY, 1, t1.[END]) = t2.[START]) >> >> UNION ALL >> >> SELECT t3.[ELEMENT], t3.[START], c.[END], t3.[VALUE] >> FROM [Test].[dbo].[Table1] t3 >> INNER JOIN CteTable c >> ON t3.[ELEMENT] = c.[ELEMENT] AND t3.[VALUE] = c.[VALUE] >> AND DATEADD(DAY, 1, t3.[END]) = c.[START] >> ), >> CteTable2 as ( >> select [ELEMENT], MIN([START]) as [START], [END], MAX([VALUE]) as [VALUE] >> from CteTable >> group by [ELEMENT], [END] >> ) >> select [ELEMENT], [START], MAX([END]) as [END], MAX([VALUE]) as [VALUE] >> from CteTable2 >> group by [ELEMENT], [START] >