Re: Adding AVG to a JOIN

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "Alexander Farber" <alexander(dot)farber(at)gmail(dot)com>
Cc: "pgsql-general" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Adding AVG to a JOIN
Date: 2018-04-23 10:15:14
Message-ID: 7fe99e8b-3fa9-4711-8688-010083fd24cf@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2018-04-23 10:56:32 Re: Adding AVG to a JOIN
Previous Message Alexander Farber 2018-04-23 08:58:45 Adding AVG to a JOIN