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;