Re: Generating subtotal reports direct from SQL

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Owen Hartnett" <owen(at)clipboardinc(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Generating subtotal reports direct from SQL
Date: 2007-10-10 00:32:12
Message-ID: 87bqb7byib.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Owen Hartnett" <owen(at)clipboardinc(dot)com> writes:

> Such that the final table has additional subtotal rows with the aggregate sum
> of the amounts. I'm thinking I can generate two tables and merge them, but is
> there an easier way using a fancy Select statement?

Unfortunately the fancy SQL feature you're looking for is ROLLUP which
Postgres doesn't support.

I think you would have to do

(
select id, code, amount from foo where code < 10
union all
select null, code, sum(amount) from foo where code < 10 group by code
) order by code, id

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Filip Rembiałkowski 2007-10-10 02:30:29 Re: How to speedup intarray aggregate function?
Previous Message pgsql.gen 2007-10-10 00:25:23 Using C API