array-agg

Equivalent of PostgreSQL's array_agg in Oracle XE 11.2 [duplicate]

有些话、适合烂在心里 提交于 2020-01-11 05:31:30
问题 This question already has answers here : SQL Query to concatenate column values from multiple rows in Oracle (11 answers) Closed 2 years ago . I have a Oracle 11g XE database and I have a query the result set: ID Category 1 Cat1 1 Cat2 2 Cat3 2 Cat4 I want to get distinct id's with all related categories in same row as comma separated like this ID Categories 1 Cat1,Cat2 2 Cat3,Cat4 I was using Postgres before and array_agg helped me there. How can I get same result in Oracle 11g XE? 回答1:

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

僤鯓⒐⒋嵵緔 提交于 2019-12-25 00:38:19
问题 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 | 4 | Tom Brown 8 | 2016-06-30 | 2 | Tom Brown 9 | 2016-06-30 | 1 | Tom Brown How can I query the table efficiently so that I can get a new column using array_agg(). I have already tried the

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

帅比萌擦擦* 提交于 2019-12-11 08:42:06
问题 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 5 | 2016-06-30 | 2 | Ben Smith 6 | 2016-06-30 | 2 | Tom Brown 7 | 2016-06-29 | 4 | Tom Brown 8 | 2016-06-30 | 2 | Tom Brown 9 | 2016-06-30 | 1 | Tom Brown How can I query the table efficiently so

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

馋奶兔 提交于 2019-12-04 15:00:39
问题 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 = logitem.log_id INNER JOIN worker u ON log.worker_id = u.id WHERE logitem.company_id = 1 Executable query is avaiable on sqlfiddle.com . Click on Run SQL button and you will result, which contains

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

喜夏-厌秋 提交于 2019-12-03 09:22:37
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 = logitem.log_id INNER JOIN worker u ON log.worker_id = u.id WHERE logitem.company_id = 1 Executable query is avaiable on sqlfiddle.com . Click on Run SQL button and you will result, which contains Frantisek Smith twice You can use the distinct keyword inside array_agg : SELECT ARRAY_TO_STRING(ARRAY_AGG

how to make array_agg() work like group_concat() from mySQL

前提是你 提交于 2019-11-29 11:04:01
问题 So I have this table: create table test ( id integer, rank integer, image varchar(30) ); Then some values: id | rank | image ---+------+------- 1 | 2 | bbb 1 | 3 | ccc 1 | 1 | aaa 2 | 3 | c 2 | 1 | a 2 | 2 | b I want to group them by id and concatenate the image name in the order given by rank. In mySQL I can do this: select id, group_concat( image order by rank asc separator ',' ) from test group by id; And the output would be: 1 aaa,bbb,ccc 2 a,b,c Is there a way I can have this in

PostgreSQL array_agg order

时间秒杀一切 提交于 2019-11-28 04:02:27
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;Mouse Can I be sure that order in first aggregate function will always be the same as in second. I mean I would't like to get: Tom;Jerry;Kermit, Frog;Mouse,Cat If you are on a PostgreSQL version < 9.0 then: From: http://www.postgresql.org/docs/8.4/static/functions-aggregate.html In the current

PostgreSQL array_agg order

天大地大妈咪最大 提交于 2019-11-27 05:11:54
问题 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;Mouse Can I be sure that order in first aggregate function will always be the same as in second. I mean I would't like to get: Tom;Jerry;Kermit, Frog;Mouse,Cat 回答1: If you are on a PostgreSQL version <