From: Daniel Verite <daniel@manitou-mail.org>
To: Alexander Farber <alexander.farber@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Adding AVG to a JOIN
Date: Mon, 23 Apr 2018 12:15:14 +0200
Message-ID: <7fe99e8b-3fa9-4711-8688-010083fd24cf@manitou-mail.org> (raw)
In-Reply-To: <CAADeyWiM21RZVsc4McqydbRxE4sNvUp-xATehfkTqjcrqG8WSA@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: daniel@manitou-mail.org, alexander.farber@gmail.com
Subject: Re: Adding AVG to a JOIN
In-Reply-To: <7fe99e8b-3fa9-4711-8688-010083fd24cf@manitou-mail.org>
References: <CAADeyWiM21RZVsc4McqydbRxE4sNvUp-xATehfkTqjcrqG8WSA@mail.gmail.com> <7fe99e8b-3fa9-4711-8688-010083fd24cf@manitou-mail.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox