Re: Adding AVG to a JOIN

2018-04-24 Thread Alexander Farber
Thank you for the explanation. I have rearranged my query and it works now (surprisingly fast too) - On Mon, Apr 23, 2018 at 9:58 PM, David G. Johnston < david.g.johns...@gmail.com> wrote: > On Mon, Apr 23, 2018 at 12:47 PM, Alexander Farber < > alexander.far...@gmail.com> wrote: > >>

Re: Adding AVG to a JOIN

2018-04-23 Thread David G. Johnston
On Mon, Apr 23, 2018 at 12:47 PM, Alexander Farber < alexander.far...@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 >

Re: Adding AVG to a JOIN

2018-04-23 Thread Alexander Farber
Good evening, On Mon, Apr 23, 2018 at 12:56 PM, Alexander Farber < alexander.far...@gmail.com> wrote: > > On Mon, Apr 23, 2018 at 12:15 PM, Daniel Verite > wrote: > >> >> You may use a correlated subquery in the SELECT clause, >> > >SELECT > u.elo, >

Re: Adding AVG to a JOIN

2018-04-23 Thread Alexander Farber
Thank you, Daniel - On Mon, Apr 23, 2018 at 12:15 PM, Daniel Verite wrote: > > 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 > thi

Re: Adding AVG to a JOIN

2018-04-23 Thread Daniel Verite
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

Adding AVG to a JOIN

2018-04-23 Thread Alexander Farber
Hello, in PostgreSQL 10.3 I run the following query to find top 10 players with the best ELO rating: # SELECT u.elo, u.uid, s.given, s.photo FROM words_users u JOIN words_social s USING (uid) WHERE u.elo > 1500 -- take the most recent record from words_social (sto