Re: Adding AVG to a JOIN

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Adding AVG to a JOIN
Дата
Msg-id CAKFQuwZj0wqBVfKpJfuyhavzvX4CkHP4m-b9AfMKTWHkA9HpBw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Adding AVG to a JOIN  (Alexander Farber <alexander.farber@gmail.com>)
Ответы Re: Adding AVG to a JOIN  (Alexander Farber <alexander.farber@gmail.com>)
Список pgsql-general
On Mon, Apr 23, 2018 at 12:47 PM, Alexander Farber <alexander.farber@gmail.com> wrote:
                SELECT
                        u.elo,
                        AVG(c.played - c.prev_played) AS avg_time_per_move,
                        (SELECT ROUND(AVG(score), 1) FROM words_moves WHERE uid = u.uid) AS score,

And I don't understand why adding a CTE has caused it, because without the CTE the GROUP BY u.elo was not required...


​Adding "AVG(c.played - c.prev_played)" directly to the top-level select statement​ column list is what turned it into a "GROUP BY" query.  When you embedded the "AVG(score)" in a subquery the GROUP BY was limited to just that subquery, and it had no other columns besides the aggregate and so didn't require a GROUP BY clause.

David J.

В списке pgsql-general по дате отправления:

Предыдущее
От: Alexander Farber
Дата:
Сообщение: Re: Adding AVG to a JOIN
Следующее
От: Tim Cross
Дата:
Сообщение: Re: Postgres and fsync