Re: Finding sequential records

Поиск
Список
Период
Сортировка
От Richard Broersma
Тема Re: Finding sequential records
Дата
Msg-id 396486430809261102j73869b8es6b325621bcfe1ea6@mail.gmail.com
обсуждение исходный текст
Ответ на Finding sequential records  (Steve Midgley <science@misuse.org>)
Ответы Re: Finding sequential records  ("Richard Broersma" <richard.broersma@gmail.com>)
Список pgsql-sql
On Fri, Sep 26, 2008 at 10:39 AM, Steve Midgley <science@misuse.org> wrote:
> drop table if exists dummy;
> create table dummy (
>  id integer primary key,
>  name varchar(255),
>  fkey_id integer
>  )
> ;

> The system should return
>
> 502163
> 502164
> 502170
> 502171


--first get all of the duplicated ids
SELECT id    FROM Dummy
GROUP BY name, fkey_id


--Next from this list find check to see if there are any sibling
immediate above or below it.

SELECT A.* FROM ( SELECT ID                 FROM Dummy            GROUP BY name, fkey_id ) AS A
INNER JOIN Dummy AS D             ON A.id - 1 = D.id             OR A.id + 1 = D.id;

-- 
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug


В списке pgsql-sql по дате отправления:

Предыдущее
От: Steve Midgley
Дата:
Сообщение: Finding sequential records
Следующее
От: "Oliveiros Cristina"
Дата:
Сообщение: Re: Finding sequential records