From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tim Barnard <tbarnard@povn.com>
Cc: Jim <jim_esti@hotmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Re: [SQL] Difficult SQL Statement
Date: Tue, 29 May 2001 09:46:03 -0400
Message-ID: <18343.991143963@sss.pgh.pa.us> (raw)
In-Reply-To: <01f101c0e7c6$9fc061a0$a519af3f@hartcomm.com>
References: <f0e3dc0b.0105230920.441e873e@posting.google.com>
<01f101c0e7c6$9fc061a0$a519af3f@hartcomm.com>
"Tim Barnard" <tbarnard@povn.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, tbarnard@povn.com, jim_esti@hotmail.com, pgsql-general@postgresql.org
Subject: Re: Re: [SQL] Difficult SQL Statement
In-Reply-To: <18343.991143963@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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