Reputation: 476
I have two tables.
table_1 :
id,value1
2015,100
table_2 :
id,target
2015,200
I want to find the percentage of achievement : table_1.value1/table_2.target=...%
.
How to create SQL
scripts in Microsoft Access and Oracle?
Upvotes: 1
Views: 52
Reputation: 331
The answer should be like this
SELECT table_1.id,table_1.value/table_2.target * 100 percentage
FROM table_1 JOIN table_2
ON table_1.id = table_2.id;
Upvotes: 0
Reputation: 729
ORACLE - to get the percent value with 2 decimal places (for example):
SELECT
table_1.id,
ROUND(table_1.value/table_2.target * 100, 2) percentage
FROM
table_1,
table_2
WHERE
table_1.id = table_2.id
Upvotes: 1
Reputation: 311103
You need to join the tables.
Assuming you mean per id:
SELECT table_1.id, value/target
FROM table_1
JOIN table_2 ON table_1.id = table_2.id
Upvotes: 3