Re: Best way to do this query?

From: JOG <jog_at_cs.nott.ac.uk>
Date: 17 Jan 2007 09:12:43 -0800
Message-ID: <1169053963.300435.191880_at_51g2000cwl.googlegroups.com>


Cimode wrote:

> JOG wrote:
>
> > SELECT A.invoiceid, A.customerid, A.date, A.amount, Max(A.date -
> > B.date)
> > FROM invoices AS A
> > INNER JOIN invoices AS B
> > ON A.customerid = B.customerid
> > GROUP BY A.customerid
> I do not see how this query could produce the desired result

It concatanates each invoice_id for a particular customer with every other invoice they have created, then calculates the most recent invoice by comparing the time differentials for each generated tuple. Ugly as sin, but it works, despite leaving you with an extraneous Max(A.date = B.date) column that essentially organizes the whole horrific fudge. Received on Wed Jan 17 2007 - 18:12:43 CET

Original text of this message