Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create a Percentage with 2 Tables

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading