pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Aggregate versus lineitem report
2+ messages / 2 participants
[nested] [flat]

* Aggregate versus lineitem report
@ 2005-10-21 15:32  Jerry Blumenthal <jerblum4@comcast.net>
  0 siblings, 1 reply; 2+ messages in thread

From: Jerry Blumenthal @ 2005-10-21 15:32 UTC (permalink / raw)
  To: 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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Aggregate versus lineitem report
@ 2005-10-29 17:20  Bruno Wolff III <bruno@wolff.to>
  parent: Jerry Blumenthal <jerblum4@comcast.net>
  0 siblings, 0 replies; 2+ messages in thread

From: Bruno Wolff III @ 2005-10-29 17:20 UTC (permalink / raw)
  To: jerry@blumenthalsoftware.com; +Cc: pgsql-sql

On Fri, Oct 21, 2005 at 11:32:13 -0400,
  Jerry Blumenthal <jerblum4@comcast.net> wrote:
> 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")

Normally you would use two separate queries to do this. If you really need to
combine them for some reason you can use UNION ALL and some contortions to
make sure the two subselects have the same number of columns and that the
rows appear in the correct order.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-10-29 17:20 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-21 15:32 Aggregate versus lineitem report Jerry Blumenthal <jerblum4@comcast.net>
2005-10-29 17:20 ` Bruno Wolff III <bruno@wolff.to>

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