首页 > 解决方案 > 如何获得两个独立数据库中行数之间的百分比?

问题描述


我有两个数据库(A 和 B)。我需要找到 A** 中的**行数和 B** 中的**行数之间的百分比(例如,如果我在 A* 中有 *100 行,在 B* 中有 *10 行,*result 将是10%*)。

有没有办法使用 **JOIN** 运算符来做到这一点?

我尝试使用“**SELECT COUNT(*) FROM DBA**”来获取 A 中的行数,但是我不知道如何构建 JOIN 语句来获取百分比。

提前致谢。

标签: mysqlsql

解决方案


您可以使用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;

推荐阅读