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.

1
  • select SUM(bar) from foo will return a single value for the entire table foo. Is this what you are trying to achieve, or is your actual requirement more complicated, and if it is more complicated, can you give us more details? Commented Sep 29, 2010 at 14:30

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

2
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.