开发者

Using Aggregate Functions in a single sql query

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, wh开发者_高级运维ich does not appear to support the two solutions posted thus far.


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜