Simple SQL query, combine results and split

I am trying to get 2 accounts from 2 tables and work out a percentage, as for mysql db

1) select field_one, count (*) as COUNT_ONE from the group table1 by field_

2) select other_field, count (*) as COUNT_TWO from group table2 to other_field;

I want to combine the results and have FINAL_COUNT = (COUNT_ONE / COUNT_TWO) * 100 for a percentage?

+7
sql mysql
source share
2 answers

quick and dirty:

select (a.count_one / b.count_two) * 100 as final_count from (select field_one, count(*) as count_one from table1 group by field_one) a, (select field_two, count(*) as count_two from table2 group by field_two) b where a.field_one = b.field_two 
+12
source share
 select sum(((QUERY FROM TABLE 1) / (QUERY FROM TABLE 2)) * 100) as percentage 
+5
source share

All Articles