Home > front end >  How to filter results of this SQL query?
How to filter results of this SQL query?

Time:10-22

I've run a query to calculate the difference between values of two columns from two tables using a common key. The query is:

Select a.GPID, a.StartDate-b.StartDate as Discrepancy FROM Difftable1 a INNER JOIN Difftable2 b ON a.GPID= b.GPID;

and the results are here:

Results

But I want to filter the results to only include differences which equal -10000. Every attempt results in a syntax error. I'm new to SQL.

CodePudding user response:

If you want to filter out -10000 from the result set, you can use

SELECT a.GPID, a.StartDate-b.StartDate as Discrepancy 
FROM Difftable1 a 
    INNER JOIN Difftable2 b ON a.GPID= b.GPID
WHERE a.StartDate-b.StartDate != -10000;

If you want to have records in the result set with only -10000, then replace != with = at the end of the above statement.

  • Related