I am new in creating table and sql.
I have two tables Region 1 and Region 2 as seen below. Now I want to create a third table in order to compute and get the percentage I already have the formula just need to have the finale table as below.
Formula: (Total / Grand Total) * 100
Region 1
| Territories | Total |
|---|---|
| NAM | 30,000 |
| EMEA | 1,375,390 |
Region 2
| Grand Total |
|---|
| 5170701 |
FINAL TABLE
| Territories | Total | % |
|---|---|---|
| NAM | 30,000 | 0.58% |
| EMEA | 1,375,390 | 26.59 |
>Solution :
The below query should work. It takes columns from those two tables and give the required output.
SELECT A.TERRITORIES, A.TOTAL, ((A.TOTAL * 100.0) / B.GRAND_TOTAL) AS PERCENTAGE FROM REGION1 A, REGION2 B;