Aggregate versus lineitem report

From: Jerry Blumenthal <jerblum4(at)comcast(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Aggregate versus lineitem report
Date: 2005-10-21 15:32:13
Message-ID: 435909FD.5040904@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

How do you get a report that lists items and then produces a sum at the
end. Like this:

name date amount1 amount2
name date amount1 amount2
name date amount1 amount2

totals sum(amount1) sum(amount2)

The sql command I am using now is

SELECT SUM(Tcode.T_amount) Fees,
SUM(Tcharges.T_discount) Discount,
Tcode.T_prov Provider
FROM "C:\zz\Tcode.DAT" Tcode
INNER JOIN "C:\zz\Tcharges.DAT" Tcharges
ON Tcode.T_acctnum = Tcharges.T_acctnum
AND Tcode.T_link = Tcharges.T_link
WHERE (((Tcode.T_posted BETWEEN "01/01/2004" AND "01/31/2004")
AND (Tcode.T_tcode < 30000)))
GROUP BY Provider

And that shows a list of amounts, for each provider, but I want to be
able to show all the line items that added up to those totals. (I didnt
include the group by provider issue in my question because that is nice
but not necessary- I can always just do one provider at a time with a
clause like "WHERE provider = 1")

TIA
Jerry

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2005-10-21 16:06:31 Re: Delete rule chain stops unexpectedly
Previous Message krishnaa sridharan 2005-10-21 15:24:11 SQL language