Re: Summary Query based on First Occurrence
- From: Jason Lepack <jlepack@xxxxxxxxx>
- Date: Tue, 12 Jun 2007 11:21:35 -0700
Is that invoice date a text field? Why not actually use a field that
would store dates? But anyways, it will still work the same.
I used a table called invoices with your table structure.
I created a query called Query1:
SELECT
Account,
Min(InvoiceDate) AS FirstInvoiceDate
FROM
Invoices
GROUP BY
Account
I then created a second query called Query2:
SELECT
Q1.Account,
Q1.FirstInvoiceDate,
Sum(I.TotBill) AS SumFirstDate
FROM
Query1 AS Q1
INNER JOIN Invoices AS I
ON Q1.Account=I.Account
AND Q1.FirstInvoiceDate=I.InvoiceDate
GROUP BY
Q1.Account,
Q1.FirstInvoiceDate
Cheers,
Jason Lepack
On Jun 12, 2:01 pm, Dave Schoenbrun
<DaveSchoenb...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I've got a list of invoices for businesses, some which have multiple invoices
on a given day. I want to be able to return ONLY the First Day a customer
was invoiced AND the TOTAL for just that day. Here's what the data looks
like:
Account InvoiceDate TotBill
A B C Corp. 20041231 3500.00
A B C Corp. 20041231 9500.00
A B C Corp. 20050131 1500.00
A B C Corp. 20050131 2000.00
BARBERS INC. 20041431 1500.00
BARBERS INC. 20041431 12000.00
BARBERS INC. 20050131 300.00
BARBERS INC. 20050131 470.00
Ideally, my Query results would look like the following:
Account InvoiceDate TotBill
A B C Corp. 20041431 13000.00
BARBERS INC. 20041431 12150.00
Any Ideas?
.
- Follow-Ups:
- Re: Summary Query based on First Occurrence
- From: Dave Schoenbrun
- Re: Summary Query based on First Occurrence
- Prev by Date: Re: Week format
- Next by Date: Re: Query Calc. is Mult. # of Table rows--Y?
- Previous by thread: Re: using dmax and date field
- Next by thread: Re: Summary Query based on First Occurrence
- Index(es):
Relevant Pages
|