tags:

views:

61

answers:

2

I'm curious if it is possible to do the following

select id from foo where foo.bar = (select SUM(bar) from foo )

without the use of a subquery.

Edit: To clarify, I'm trying to do this with postgresql, which does not appear to support the two solutions posted thus far.

+2  A: 

You can try a similar thing using joins, although it is less clear than the subquery

SELECT f1.id
FROM foo f1
CROSS JOIN foo f2
WHERE f1.bar = SUM(f2.bar)
GROUP BY f1.id, f1.bar
JamesMLV
+2  A: 
Its not possible to write it without sub query
see the Below Link for more Help
http://www.postgresql.org/docs/8.1/static/tutorial-agg.html
Avadhesh