Re: STRING_AGG and GROUP BY

Поиск
Список
Период
Сортировка
От Alexander Farber
Тема Re: STRING_AGG and GROUP BY
Дата
Msg-id CAADeyWjAc21emBjQUV0Uv-xWXAhZAmT=L+X1TZV5p5V3zNwqGw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: STRING_AGG and GROUP BY  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: STRING_AGG and GROUP BY
Список pgsql-general
Hi David -

On Fri, Mar 16, 2018 at 4:40 PM, David G. Johnston <david.g.johnston@gmail.com> wrote:
​First reaction is to ARRAY_AGG(DISTINCT x) and then write a function that converts ​that array into a string by extracting 'letter' from each cell in the array.

Thinking it over a bit you have two columns that both are aggregates but that are otherwise independent of each other.  Since they are independent they cannot be aggregated at the same time.  You need to write a two subqueries, either in the target list or as separate from/join items, and then join the already aggregated queries together on their common group by column.

The presence of DISTINCT here (and, IMO, generally), even if it worked, would be an indicator that something is not quite right.


thank you for confirming my feeling that DISTINCT is a bad indicator here...

But you say that "tiles" and  "word (score)" are unrelated and this does not seem true to me:

For each move id aka "mid" there is a JSON value, describing how the player played the letter tiles.
And for the same "mid" there is a list of one or more "word (score)"s achieved...

Maybe it is possible to GROUP BY tiles somehow or some kind of special SQL JOIN?

Regards
Alex

В списке pgsql-general по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: STRING_AGG and GROUP BY
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: STRING_AGG and GROUP BY