pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: M. D. <lists@turnkey.bz>
To: pgsql-sql@postgresql.org
Subject: group by with sum and sum till max date
Date: Tue, 05 Jul 2011 11:42:10 -0600
Message-ID: <4E134CF2.1040304@turnkey.bz> (raw)

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



view thread (2+ messages)  latest in thread

Message-ID: <4E134CF2.1040304@turnkey.bz>
Permalink:  ../4E134CF2.1040304@turnkey.bz/
Also on:    postgresql.org/message-id/4E134CF2.1040304@turnkey.bz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: lists@turnkey.bz
  Subject: Re: group by with sum and sum till max date
  In-Reply-To: <4E134CF2.1040304@turnkey.bz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox