Re: [SQL] sum of two queries

From: "G(dot) Anthony Reina" <reina(at)nsi(dot)edu>
To: Kyle Bateman <kyle(at)actarg(dot)com>, "pgsql-sql(at)postgreSQL(dot)org" <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: [SQL] sum of two queries
Date: 1999-04-22 21:23:54
Message-ID: 371F936A.142DBA48@nsi.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Kyle Bateman wrote:

>>
>
> I explained my problem badly.
>
> Here's the full thing. I'm doing this, which works:
>
> select -sum(tquant) from mtr_reg where
> status = 'clsd' and
> fr_proj = 20 and
> pnum = '1122'
> union
> select sum(tquant) from mtr_reg where
> status = 'clsd' and
> to_proj = 20 and
> pnum = '1122'
> ;

I think this will work (it seems to work when I tried it with my
database):

select sum(a.tquant - b.tquant) from mtr_reg as a, mtr_reg as b where
a.status = 'clsd' and
b.status = 'clsd' and a.pnum = '1122' and b.pnum = '1122' and a.fr_proj
= 20 and b.to_proj = 20;

-Tony

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael J Davis 1999-04-22 21:42:33 RE: [SQL] SELECT TOP X -- part 2 -- parse error?
Previous Message Justin Long 1999-04-22 21:23:33 RE: [SQL] SELECT TOP X -- part 2 -- parse error?