Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4TDkGE96292 for ; Tue, 29 May 2001 09:46:16 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.3/8.11.3) with ESMTP id f4TDk3R18346; Tue, 29 May 2001 09:46:07 -0400 (EDT) To: "Tim Barnard" cc: "Jim" , pgsql-general@postgresql.org Subject: Re: Re: [SQL] Difficult SQL Statement In-reply-to: <01f101c0e7c6$9fc061a0$a519af3f@hartcomm.com> References: <01f101c0e7c6$9fc061a0$a519af3f@hartcomm.com> Comments: In-reply-to "Tim Barnard" message dated "Mon, 28 May 2001 15:36:22 -0700" Date: Tue, 29 May 2001 09:46:03 -0400 Message-ID: <18343.991143963@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200105/1130 X-Sequence-Number: 10180 "Tim Barnard" writes: > To my thinking there's got to be a better way to do this whithout so many > temporary tables. In 7.1 you can frequently replace temp tables with subselect-in-FROM. Cutting-and-pasting freely from your solution: select ASMT_CODE, PASSED, TOTAL, PASSED::float4/TOTAL::float4 from (select ASMT_CODE, count(*) as TOTAL from RESULTS group by ASMT_CODE) as tmp1 natural join (select ASMT_CODE, count(*) as PASSED from RESULTS where STATUS='PASSED' group by ASMT_CODE) as tmp2 (haven't tried this, but it looks right...) This won't necessarily be a whole lot faster than the solution with temp tables, but it's nice not to have to worry about dropping the temp tables afterwards. regards, tom lane