Received: from nsi.edu (amethea.nsi.edu [198.133.185.9]) by hub.org (8.9.3/8.9.1) with ESMTP id RAA17945 for ; Thu, 22 Apr 1999 17:24:05 -0400 (EDT) (envelope-from reina@nsi.edu) Received: from nsi.edu (o21.nsi.edu [204.128.156.216]) by nsi.edu (8.9.1/8.9.1) with ESMTP id OAA29696; Thu, 22 Apr 1999 14:23:59 -0700 (PDT) Sender: reina@nsi.edu Message-ID: <371F936A.142DBA48@nsi.edu> Date: Thu, 22 Apr 1999 14:23:54 -0700 From: "G. Anthony Reina" Organization: The Neurosciences Institute X-Mailer: Mozilla 4.07C-SGI [en] (X11; I; IRIX 6.5 IP32) MIME-Version: 1.0 To: Kyle Bateman , "pgsql-sql@postgreSQL.org" Subject: Re: [SQL] sum of two queries References: <371F5BBF.874251FD@actarg.com> <371F5CE9.98C540FD@nsi.edu> <371F6724.C05E431@actarg.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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