database - Element-wise quotient of two columns in SQL -


how can combine columns returned 2 select statements give element-wise quotient?

query 1:

select count(*) count table1 col2 = 1 , col3 > 5 group col4 order col4 

query 2:

select count(*) count table1 col2 = 1 group col4 order col4 

so if return like:

query 1        query 2 count           count ----------------------- 1              5 2              4 

i get:

quotient ------- 0.2 0.5 

with 4-column version of question, can assume quotient between groups same value in col4. so, answer becomes:

select col4, sum(case when col3 > 5 1 else 0 end) / count(*) quotient   table1  col2 = 1  group col4; 

i've retained col4 in output because don't think ratios (quotients) useful without identify quotient associated values, though theoretically, answer doesn't want column in output.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -