Re: grouping/clustering query - Mailing list pgsql-sql

From Steve Midgley
Subject Re: grouping/clustering query
Date
Msg-id 20081023160857.220D164FD12@postgresql.org
Whole thread Raw
In response to grouping/clustering query  ("David Garamond" <davidgaramond@gmail.com>)
Responses Re: grouping/clustering query  (Joe <dev@freedomcircle.net>)
List pgsql-sql
At 10:20 PM 10/22/2008, you wrote:
>Message-ID: 
><7c33d060810212214h5c85b406i49dd9e8d76bec9bd@mail.gmail.com>
>Date: Wed, 22 Oct 2008 12:14:49 +0700
>From: "David Garamond" <davidgaramond@gmail.com>
>To: pgsql-sql@postgresql.org
>Subject: grouping/clustering query
>X-Archive-Number: 200810/89
>X-Sequence-Number: 31731
>
>Dear all,
>
>I have an invoices (inv) table and bank transaction (tx) table.
>There's also the payment table which is a many-to-many relation
>between the former two tables, because each invoice can be paid by one
>or more bank transactions, and each bank transaction can pay for one
>or more invoices. Example:
>
># (invoiceid, txid)
>(A, 1)
>(A, 3)
>(B, 1)
>(B, 2)
>(C, 5)
>(D, 6)
>(D, 7)
>(E, 8)
>(F, 8)
>
>For journalling, I need to group/cluster this together. Is there a SQL
>query that can generate this output:
>
># (journal: invoiceids, txids)
>[A,B] , [1,2,3]
>[C], [5]
>[D], [6,7]
>[E,F], [8]

Hi Dave,

I'm not following the logic here. A has 1,3 and B has 1,2. So why does 
the first line print:

>[A,B] , [1,2,3]

What's the rule that tells the query to output this way? Is it that all 
of B's values are between A's values?

Also in your output, you've indicated [A,B] - does this mean you want 
two columns of output, each column being a pg array?

I may not be the best person to answer the actual SQL question, but I 
thought I'd clarify your requirements so the list members can have the 
best chance of answering.

Steve



pgsql-sql by date:

Previous
From: "Oliveiros Cristina"
Date:
Subject: Re: Postgres-sql-php
Next
From: "Oliveiros Cristina"
Date:
Subject: Re: Postgres-sql-php