mysql - 如何获得两个独立数据库中行数之间的百分比?
问题描述
我有两个数据库(A 和 B)。我需要找到 A** 中的**行数和 B** 中的**行数之间的百分比(例如,如果我在 A* 中有 *100 行,在 B* 中有 *10 行,*result 将是10%*)。
有没有办法使用 **JOIN** 运算符来做到这一点?
我尝试使用“**SELECT COUNT(*) FROM DBA**”来获取 A 中的行数,但是我不知道如何构建 JOIN 语句来获取百分比。
提前致谢。
解决方案
您可以使用cross join
:
select cnt_a, cnt_b, cnt_b * 100.0 / cnt_a as percentage
from (select count(*) as cnt_a from a) a cross join
(select count(*) as cnt_b from b) b;
推荐阅读
- c - 如何在结构中的数组列表中正确分配和释放二维数组的内存?
- python-3.x - 将用户输入与字符串列表进行比较
- spring - 别名 apollo 的密钥没有私钥
- javascript - Node.js 中缓冲区的二进制字符串
- javascript - 为什么我的 CSS 背景图像没有加载到电子中?
- r - 使用 mcmapply 从父函数调用的嵌套函数内部将 R 对象保存到全局环境
- javascript - Auth0静默身份验证无法在移动设备上运行,在其他地方也可以正常工作
- javascript - 使用路由器视图将值传递给所有路由
- javascript - 无法让段落元素在出现时淡出过渡
- javascript - CSS/Flexbox:Flex 项目上的滚动条?