Skip to content
Advertisement

How to get percentage between number of rows in two separate databases?


I have two databases (A and B). I need to find the percentage between number of **rows in A** and number of **rows in B** (for example, if I have *100 rows in A* and *10 in B*, *result will be 10%*).

Is there a way to do so using **JOIN** operator?

I tried with “**SELECT COUNT(*) FROM DBA**” to get the number of rows in A, but then I don’t know how to build the JOIN statement to get the percentage.

Thanks in advance.

Advertisement

Answer

You can use 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;
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement