group-concat

Concatenate and group multiple rows in Oracle [duplicate]

半城伤御伤魂 提交于 2020-01-08 17:15:12
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: how to retrieve two columns data in A,B format in Oracle Suppose I have a table like this: NAME GROUP_NAME name1 groupA name2 groupB name5 groupC name4 groupA name3 groupC I'd like to have a result like this: GROUP_NAME NAMES groupA name1,name4 groupB name2 groupC name3,name5 If there were only one column in the table, I could concatenate the records by doing the following, but with grouping in the context, I

Concatenate and group multiple rows in Oracle [duplicate]

感情迁移 提交于 2020-01-08 17:15:10
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: how to retrieve two columns data in A,B format in Oracle Suppose I have a table like this: NAME GROUP_NAME name1 groupA name2 groupB name5 groupC name4 groupA name3 groupC I'd like to have a result like this: GROUP_NAME NAMES groupA name1,name4 groupB name2 groupC name3,name5 If there were only one column in the table, I could concatenate the records by doing the following, but with grouping in the context, I

Show a one to many relationship as 2 columns - 1 unique row (ID & comma separated list)

被刻印的时光 ゝ 提交于 2020-01-08 13:22:12
问题 I need something similar to these 2 SO questions, but using Informix SQL syntax. Concatenate several fields into one with SQL SQL Help: Select statement Concatenate a One to Many relationship My data coming in looks like this: id codes 63592 PELL 58640 SUBL 58640 USBL 73571 PELL 73571 USBL 73571 SUBL I want to see it come back like this: id codes 63592 PELL 58640 SUBL, USBL 73571 PELL, USBL, SUBL See also group_concat() in Informix. 回答1: I believe that the answer you need is a user-defined

select query into list on one column

自作多情 提交于 2020-01-07 05:43:26
问题 I am trying to select all id into one column and delimit it with a comma , My DATA column: +---+--------+--------------+ |id |somedata|someother data| +---+--------+--------------+ |1 |data1 |other1 | +---+--------+--------------+ |2 |data2 |other2 | +---+--------+--------------+ |3 |data3 |other3 | +---+--------+--------------+ The result I am trying to make: +-------+ |id list| +-------+ |1, 2, 3| +-------+ The result should be a list of ID's in 1 column named 'id list'. The question is, is

sql group_concat and subquery

喜你入骨 提交于 2020-01-04 05:32:11
问题 I have 2 mysql tables: car_model: id (int) (Primary Key) title (varchar) id_brand (int) FK to car_brand table car__car_model: - relation many to many id_model (int) id_advice_model (int) In car__car_model there are the following data: (id_model) (id_advice_model) 12 12 12 45 12 67 12 78 13 13 13 12 13 67 13 105 And I want to fetch this data like this: 12 12,45,67,78 13 13.12.67,105 I use group_concat and group by like this: SELECT ccm.id_model,group_concat(ccm.id_advice_model) FROM car__car

mysql GROUP_CONCAT

*爱你&永不变心* 提交于 2020-01-01 10:00:31
问题 I want to list all users with their corropsonding user class. Here are simplified versions of my tables CREATE TABLE users ( user_id INT NOT NULL AUTO_INCREMENT, user_class VARCHAR(100), PRIMARY KEY (user_id) ); INSERT INTO users VALUES (1, '1'), (2, '2'), (3, '1,2'); CREATE TABLE classes ( class_id INT NOT NULL AUTO_INCREMENT, class_name VARCHAR(100), PRIMARY KEY (class_id) ); INSERT INTO classes VALUES (1, 'Class 1'), (2, 'Class 2'); And this is the query statement I am trying to use but is

How to execute a query which is stored in a table column MySQL?

自古美人都是妖i 提交于 2020-01-01 06:35:25
问题 mysql> select * from CT; | CID | MID | REPORT_QUERY | | 1 | 1 | select * from emp; | | 2 | 2 | select * from student; | 2 rows in set (0.00 sec) I want to execute queries in REPORT_QUERY column. DELIMITER // CREATE PROCEDURE TRYct() BEGIN SET @str=(SELECT GROUP_CONCAT(REPORT_QUERY SEPARATOR ' ') FROM CT); PREPARE q from @str; EXECUTE q; END // DELIMITER ; i use this code but it works if there is only one query in my table. if there is two query than it gives an error. ERROR 1064 (42000): You

How to use GROUP_CONCAT with Zend Framework?

本秂侑毒 提交于 2019-12-30 03:31:05
问题 Assume that I have a table : students ______________________________________________________ |id | name | school | class | ______________________________________________________ | 1 | John | ABC | C1 | | 2 | Jack | ABC | C1 | | 3 | Anna | ABC | C1 | | 4 | Peter | DEF | D1 | | 5 | Alex | ABC | C2 | | 6 | Bryan | ABC | C2 | | 7 | David | ABC | C2 | | 8 | Cristian | DEF | D1 | _______________________________________________________ Using this query : SELECT a.class,GROUP_CONCAT(a.name) as names

mysql GROUP_CONCAT duplicates

纵然是瞬间 提交于 2019-12-28 02:49:15
问题 I make my join from a farmTOanimal table like this. There is a similar farmTotool table id | FarmID | animal 1 | 1 | cat 2 | 1 | dog When I join my tables in a view, I get a result that looks like this FarmID | animal | tool 1 | cat | shovel 1 | dog | shovel 1 | cat | bucket 1 | dog | bucket Now, I do GROUP BY FarmID, and GROUP_CONCAT(animal) and GROUP_CONCAT(tool), i get FarmID | animals | tools 1 | cat,dog,cat,dog | shovel,shovel,bucket,bucket But, what I really want is a result that looks

MySql join multiple tables with different rows number

僤鯓⒐⒋嵵緔 提交于 2019-12-25 08:06:15
问题 I'm sorry for the probably confusing title but I didn't really know how to describe my problem well. I also appologize for my english as I'm not a native speaker. Let's say I have this schema : _________ _________ | Table 1 | | Table 2 | |---------| ______ ________|---------| | id_a |___ | join | | | id_b | | name | | |------| | | info | |_________| |_____| id_a |___| | data | | id_b | |_________| |______| With these informations in the database : Table 1 : _____________ | id_a | name | |----