Re: grouping subsets
От | A. Kretschmer |
---|---|
Тема | Re: grouping subsets |
Дата | |
Msg-id | 20100722100226.GE10348@a-kretschmer.de обсуждение исходный текст |
Ответ на | grouping subsets (Rainer Stengele <rainer.stengele@diplan.de>) |
Ответы |
Re: grouping subsets
|
Список | pgsql-sql |
In response to Rainer Stengele : > Hi, > > having a table similar to > > | 1 | B | [2010-07-15 Do] | > | 1 | B | [2010-07-16 Fr] | > |---+---+-----------------| > | 2 | C | [2010-07-17 Sa] | > | 2 | C | [2010-07-18 So] | > |---+---+-----------------| > | 1 | B | [2010-07-19 Mo] | > | 1 | B | [2010-07-20 Di] | > | 1 | B | [2010-07-21 Mi] | > | 1 | B | [2010-07-22 Do] | > |---+---+-----------------| > | 3 | D | [2010-07-23 Fr] | > > a simple group by gives me: > > | 6 | B | > | 4 | C | > | 3 | D | > > > What I want to get is the values grouped by "subset", where a subset is a set of rows with identical column until the columchanges. > Is there a way to get > > | 2 | B | > | 4 | C | > | 4 | B | > | 3 | D | > > by SQL only? I think, the problem is that there are 2 identical groups. I think, you can write a pl/pgsql-proc, selecting all ordered by the date-field and walking through the result to do the grouping, checking if the 2nd column is different from the previous. With plain SQL it's maybe possible too, but i don't know how ... Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99
В списке pgsql-sql по дате отправления: