Re: Adding AVG to a JOIN - Mailing list pgsql-general

From Daniel Verite
Subject Re: Adding AVG to a JOIN
Date
Msg-id 7fe99e8b-3fa9-4711-8688-010083fd24cf@manitou-mail.org
Whole thread Raw
In response to Adding AVG to a JOIN  (Alexander Farber <alexander.farber@gmail.com>)
Responses Re: Adding AVG to a JOIN  (Alexander Farber <alexander.farber@gmail.com>)
List pgsql-general
    Alexander Farber wrote:

> Here is such a query for the best player
>
> # SELECT AVG(score) FROM words_moves WHERE uid = 1201;
>         avg
> ---------------------
> 18.4803525523319868
>
> However I am not sure, how to "marry" the 2 queries?
>
> I have tried to add words_moves through another JOIN, but that does not
> work:

You may use a correlated subquery in the SELECT clause,
like this:

 SELECT
       u.elo,
       u.uid,
       (SELECT AVG(score) FROM words_moves WHERE uid=u.uid),
       s.given,
       s.photo


Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite


pgsql-general by date:

Previous
From: Alexander Farber
Date:
Subject: Adding AVG to a JOIN
Next
From: Alexander Farber
Date:
Subject: Re: Adding AVG to a JOIN