Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

group by date

Status
Not open for further replies.

yuchieh

MIS
Jul 21, 2000
178
US
I have a table that stores donation information - name, transaction_date, amount, fund

how do I select:
total amount >= $100 accumulated in one day, by one person?
and yet, I need to display details. in other words, display individual records if the total amount belongs to multiple funds.

Thanks

 
You do this in two pieces. First, find the aggregate criteria, then join to the details

Code:
SELECT b.*, a.DailyAmount
FROM

(SELECT 
DateColumn,
PersonColumn,
SUM(Amount) AS DailyAmount
FROM YourTable
GROUP BY DateColumn, PersonColumn
HAVING SUM(Amount) >= 100) a

INNER JOIN

YourTable b

ON a.DateColumn = b.DateColumn
AND a.PersonColumn = b.PersonColumn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top