How to select difference using sql?
- by ganuke
I wrote a sql query to retrieve data as follows:
SELECT (MAX (b.filledqty) - MAX (a.filledqty)) AS filledtoday
FROM clientordermas a,
clientordermas b
WHERE a.clordid = 'w9110126'
AND b.clordid = 'w9110126'
AND (SELECT max(a.price)
FROM clientordermas a
WHERE a.clordid = 'w9110126') < 1000;
There are three records in the table for the given clordid with price values 800, 900
1200.
So, what I need is to get the difference between 1200 and 900 which is 300.
But, the above statement always returns 0. What I should get is
MAX (b.filledqty) retuns 1200
and
MAX (a.filledqty) retuns 900.
But it is not happening. This is not the exact problem I am facing but a simplified version of it.
Can someone please help?