Ok , consider I have a Database with one table call it Table A .
Table A Have Id int ,sum int.
Supose I want the sum values of table A that are greater than the Average of sum values.
For this I made two queries :
(SELECT AVG(sum) AS mes FROM TableA) b
a.sum > (SELECT AVG(a.sum))
yes those two queries are not equal. because in first query you are treating them as two individual tables and get the result set and finally compare it.
but in second query your performing aggregate function in that case you will get average for individual a.id
execute this you will understand what i mean
Select a.id from TableA a where a.sum = (Select avg(a.sum)) group by a.id;