Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the difference between two values

I got totally stuck on comparing two tables and getting the difference between them

So here we go: I got table a with the following columns Name|Value|Date

and the second table b with the same columns

What i wanna do now is get the difference between the values like

Table a

Name|Value|Date

Test|3|2013-20-06

Table b

Name|Value|Date

Test|9|2013-20-06

What i wann get is the difference between the 3 and 9 so i would recieve 6

Any Idea how i'm able to get that from a query in my PostgreSQL-DB?

like image 396
ZeroGS Avatar asked Jun 20 '13 13:06

ZeroGS


People also ask

How do you find the difference between values?

When the difference between two values is divided by the average of the same values, a percentage difference calculation has occurred. The formula for percentage difference looks like this: Percentage difference = Absolute difference / Average x 100.

How do you find the of difference between two numbers?

Percentage Difference Formula The percentage difference between two values is calculated by dividing the absolute value of the difference between two numbers by the average of those two numbers. Multiplying the result by 100 will yield the solution in percent, rather than decimal form.

What is the difference between two values called?

Given two numerical quantities, x and y, their difference, Δ = x − y, can be called their actual difference. When y is a reference value (a theoretical/actual/correct/accepted/optimal/starting, etc. value; the value that x is being compared to) then Δ is called their actual change.


1 Answers

Join the tables and select the difference:

select a.name, b.value - a.value, a.date 
from a inner join b on a.name = b.name and a.date = b.date
like image 160
Klas Lindbäck Avatar answered Oct 31 '22 12:10

Klas Lindbäck