开发者

Using Aggregate Functions in a single sql query

开发者 https://www.devze.com 2023-01-18 04:40 出处:网络
I\'m curious if it is possible to do the following select id from foo where foo.bar = (select SUM(bar) from foo

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

精彩评论

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

关注公众号