Get the difference between two values

16,596

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
Share:
16,596

Related videos on Youtube

ZeroGS
Author by

ZeroGS

Startet coding small php scripts and html pages back in 1999. I'm a complete self-educated person when it comes to Computer Science and Coding. My repertoire in programing languages ranges from PHP & PERL, to JAVA and C# (My favourite since a few Years) to C++ and a bit of C. I've worked in the Software Industry for 10 Years now and i've worked for Company's in Germany and Switzerland. Did some self-employed project-based Software for Company's in the UK, US, Canada, Germany, Switzerland, Austria and Australia. I surely don't know everything but like one once said, there are many ways to get to rome ;)

Updated on June 04, 2022

Comments

  • ZeroGS
    ZeroGS almost 2 years

    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?

    • Angelo Fuchs
      Angelo Fuchs almost 11 years
      do you want to know if this specific column is different or do you want to know for all columns? Say if the Name changes or the Date? You want to know as well?