Howto embed select statements into other select statements
- From: Niels Dybdahl <niels.dybdahl@xxxxxxxxx>
- Date: 7 May 2007 03:40:46 -0700
Hi,
I want to calculate the fraction of two counts and I have created the
following select statement:
select
field1,
field2,
(select table1.co/table2.co
from (select count(1) co, id from t_table1 where seal>=1000 group
by id) table1,
(select count(1) co, id from t_table2 group by id) table2
where table1.id=j.id and table2.id=j.id),
field3
from t_table3 j
This works as long as there are corresponding entries in t_table1 and
t_table2, otherwise the fraction becomes null, which might make sense
when there is nothing in t_table2 but not when t_table1 has no
matching entries.
Instead I have tried:
select
field1,
field2,
(select table1.co/table2.co
from (select count(1) co, id from t_table1 where seal>=1000 and
id=j.id) table1,
(select count(1) co, id from t_table2 where id=j.id) table2),
field3
from t_table3 j
But then the database (Oracle 10) complains that it can not find j.id.
How can I write this select correctly?
Best regards
Niels Dybdahl
.
- Follow-Ups:
- Re: Howto embed select statements into other select statements
- From: Tonkuma
- Re: Howto embed select statements into other select statements
- From: Ed Prochak
- Re: Howto embed select statements into other select statements
- Prev by Date: Re: general question about how best to cache expensive query results
- Next by Date: Re: general question about how best to cache expensive query results
- Previous by thread: Schema for Full Text DB Using Stemmer
- Next by thread: Re: Howto embed select statements into other select statements
- Index(es):
Relevant Pages
|