Re: Re: [SQL] Difficult SQL Statement
| От | Tom Lane |
|---|---|
| Тема | Re: Re: [SQL] Difficult SQL Statement |
| Дата | |
| Msg-id | 18343.991143963@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Re: [SQL] Difficult SQL Statement ("Tim Barnard" <tbarnard@povn.com>) |
| Ответы |
Re: Re: [SQL] Difficult SQL Statement
|
| Список | pgsql-general |
"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
В списке pgsql-general по дате отправления: