From: | "M(dot) D(dot)" <lists(at)turnkey(dot)bz> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | group by with sum and sum till max date |
Date: | 2011-07-05 17:42:10 |
Message-ID: | 4E134CF2.1040304@turnkey.bz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
This is a little hard to explain, and I'm not sure if it's possible, but
here goes.
This is my query:
select year, month,
(select number from account where account.account_id =
view_account_change.account_id) as number,
(select name from account where account.account_id =
view_account_change.account_id) as account,
sum(amount) as amount
from view_account_change
where view_account_change.change_date >= '2010-01-01'
group by year,month, number, account
order by year,month, number, account
I want to make an exception for the sum so that if the account number is
less than 4000, I want a sum of all transactions until the last date of
the group by.
the query for that would be:
Select sum(amount) from view_account_change where change_date > "max
date in the group"
Is this possible?
Thanks,
Mark
From | Date | Subject | |
---|---|---|---|
Next Message | Samuel Gendler | 2011-07-05 19:38:19 | Re: interesting sequence |
Previous Message | John Fabiani | 2011-07-05 13:52:22 | interesting sequence |