Re: Adding AVG to a JOIN
| От | Daniel Verite |
|---|---|
| Тема | Re: Adding AVG to a JOIN |
| Дата | |
| Msg-id | 7fe99e8b-3fa9-4711-8688-010083fd24cf@manitou-mail.org обсуждение исходный текст |
| Ответ на | Adding AVG to a JOIN (Alexander Farber <alexander.farber@gmail.com>) |
| Ответы |
Re: Adding AVG to a JOIN
|
| Список | 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 по дате отправления: