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

From Joe
Subject Re: grouping/clustering query
Date
Msg-id 4900C251.5040005@freedomcircle.net
Whole thread Raw
In response to Re: grouping/clustering query  (Steve Midgley <science@misuse.org>)
Responses Re: grouping/clustering query  (Steve Midgley <science@misuse.org>)
List pgsql-sql
Steve Midgley wrote:
>> # (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?
From a purely accounting standpoint, since transaction 1 was applied to 
both invoices A and B, you need to group the invoices so that you can 
compare total invoiced against total paid.

Joe


pgsql-sql by date:

Previous
From: "Oliveiros Cristina"
Date:
Subject: Re: Postgres-sql-php
Next
From: Steve Midgley
Date:
Subject: Re: grouping/clustering query