array-agg

PostgreSQL array_agg order

Table 'animals': animal_name animal_type Tom Cat Jerry Mouse Kermit Frog Query: SELECT array_to_string(array_agg(animal_name),';') animal_names, array_to_string(array_agg(animal_type),';') animal_types FROM animals; Expected result: Tom;Jerry;Kerimt, Cat;Mouse;Frog OR Tom;Kerimt;Jerry, Cat;Frog

PostgreSQL array_agg order

Table 'animals': animal_name animal_type Tom Cat Jerry Mouse Kermit Frog Query: SELECT array_to_string(array_agg(animal_name),';') animal_names, array_to_string(array_agg(animal_type),';') animal_types FROM animals; Expected result: Tom;Jerry;Kerimt, Cat;Mouse;Frog OR Tom;Kerimt;Jerry, Cat;Frog

Query table with array_agg of ALL previous positions, excluding current position

I have a database table with: id | date | position | name -------------------------------------- 1 | 2016-06-29 | 9 | Ben Smith 2 | 2016-06-29 | 1 | Ben Smith 3 | 2016-06-29 | 5 | Ben Smith 4 | 2016-06-29 | 6 | Ben Smith 5 | 2016-06-30 | 2 | Ben Smith 6 | 2016-06-30 | 2 | Tom Brown 7 | 2016-06-29 |

Query table with array_agg/median of ALL previous positions, LAST_10, LAST_50, excluding current position

This is a variation on this brilliantly answered question I posted previously : I have a database table with: id | date | position | name -------------------------------------- 1 | 2016-06-29 | 9 | Ben Smith 2 | 2016-06-29 | 1 | Ben Smith 3 | 2016-06-29 | 5 | Ben Smith 4 | 2016-06-29 | 6 | Ben Smith

How to remove duplicates, which are generated with array_agg postgres function

Does anyone an idea how to rewrite following SQL query to generate results, that would contains only one occurrence of name? (results grouped by user). The query SELECT array_to_string(array_agg(CONCAT(u.firstname, ' ', u.lastname)), ', ') FROM log_has_item logitem INNER JOIN log log ON log.id =

PostgreSQL array_agg order

Table 'animals': animal_name animal_type Tom Cat Jerry Mouse Kermit Frog Query: SELECT array_to_string(array_agg(animal_name),';') animal_names, array_to_string(array_agg(animal_type),';') animal_types FROM animals; Expected result: Tom;Jerry;Kerimt, Cat;Mouse;Frog OR Tom;Kerimt;Jerry, Cat;Frog