I am having an issue with SQL select statement. I am trying to get the percentage using below logic.
For example, I have two tables. One is TableA and another TableB
TableA has column ID, A1, A2.., Get total distinct count of A1 as "X".
TableB has column ID, B1, B2, FK_A1. Get count of B2 as "Y".
Get (Y/X)*100 as Total Percentage.
I was able to do it using subqueries but would like to use a simple and effective statement. Is it possible to get all the above 3 cases in one select statement? Your help would be highly appreciated.
Select
(Select count(distinct A1) from TableA) As C1,
(Select count(B2) from TableB Inner Join TableA ON TableB.FK_A1=TableA.A1)
C2)