OK, here is what I want to really do:
I need to write a single SQL query to do the following:
select count(1) from TableA where [condition1]/ select count(1) from TableA where [condition2]
One way of doing it is:
select (t.numerator/t.denominator) as ratio from (select (select count(1) from TableA where [condition1]) as numerator, (select count(1) from TableA where [condition2]) as denominator ) t
However, the tool into which I have to feed this query does not like such a long 'from' clause. Also, the option of making a view is not permissable.
So I want to find the numerator and denominator in the 'where' clause and divide them in the select clause.
Something like this:
select numerator/ denominator
where numerator = (select query using TableA with some conditions)
and denominator = (select query using TableA with another set of conditions)