我正试图从 2个表中获取 2个计数并计算出与MySQL数据库相同的百分比:
select field_one, count(*) as COUNT_ONE from table1 group by field_one;
select other_field,count(*) as COUNT_TWO from table2 group by other_field;
我想要合并结果并获得FINAL_COUNT=(COUNT_ONE/COUNT_TWO) * 100
百分比?
答案 0 :(得分:17)
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
答案 1 :(得分:5)
select sum(((QUERY FROM TABLE 1) / (QUERY FROM TABLE 2)) * 100) as percentage