简单的SQL查询,合并结果并划分 [英] simple sql query, combine results and divide

查看:85
本文介绍了简单的SQL查询,合并结果并划分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 2个表中获得 2个计数,并计算出与MySQL数据库类似的百分比:

I'm trying to get 2 counts from 2 tables and work out the percentage like for a MySQL db:

  1. 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表示百分比?

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

推荐答案

快速又肮脏:

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

这篇关于简单的SQL查询,合并结果并划分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆