Skip site navigation (1) Skip section navigation (2)

grouping/clustering query

From: "David Garamond" <davidgaramond(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: grouping/clustering query
Date: 2008-10-22 05:14:49
Message-ID: 7c33d060810212214h5c85b406i49dd9e8d76bec9bd@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
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]

Regards,
dave

pgsql-sql by date

Next:From: Oleg BartunovDate: 2008-10-23 06:52:12
Subject: Re: Full Text Index Stats
Previous:From: Ryan HansenDate: 2008-10-20 19:32:34
Subject: Full Text Index Stats

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group