How to select difference using sql?
Posted
by
ganuke
on Stack Overflow
See other posts from Stack Overflow
or by ganuke
Published on 2011-03-11T14:21:12Z
Indexed on
2011/03/11
16:10 UTC
Read the original article
Hit count: 330
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?
© Stack Overflow or respective owner