[英]simple sql query, combine results and divide
I'm trying to get 2 counts from 2 tables and work out the percentage like for a MySQL db: 我试图从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;
I want to combine the results and have FINAL_COUNT=(COUNT_ONE/COUNT_TWO) * 100
for percentage ? 我想要结合结果并获得FINAL_COUNT=(COUNT_ONE/COUNT_TWO) * 100
的百分比?
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
select sum(((QUERY FROM TABLE 1) / (QUERY FROM TABLE 2)) * 100) as percentage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.