Re: difference between 'where' and 'having'
От | Richard Broersma |
---|---|
Тема | Re: difference between 'where' and 'having' |
Дата | |
Msg-id | 396486430804281245h375d6d2cu4add4b85c1e59ac4@mail.gmail.com обсуждение исходный текст |
Ответ на | difference between 'where' and 'having' ("Adam Šindelář" <adam.sindelar@gmail.com>) |
Список | pgsql-novice |
On Mon, Apr 28, 2008 at 12:22 PM, Adam Šindelář <adam.sindelar@gmail.com> wrote: > Expressions in the HAVING clause can refer both to grouped expressions and > to ungrouped expressions (which necessarily involve an aggregate function). True, however, when constraing data in a having clause, alot more data will be processed before it is grouped. This mean that putting all of the costraints in the having clause will result in poorly performing queries. > I've been happily working with Postgres for a long time, and not once have I > ever used a HAVING in my queries, even in fairly complex ones, and I just > can't bear the suspense anymore! :) I only use the HAVING clause in cases where the where clause cannot easy constrain the data without a sub-query. SELECT AVG( X ), y FROM Thetable WHERE y > 10 GROUP BY Y HAVING AVG( X ) > 3 AND COUNT( * ) > 10 AND MAX( X ) < 10; -- Regards, Richard Broersma Jr.
В списке pgsql-novice по дате отправления: