group-concat

Accomplishing MYSQL's Group_Concat in SQL Server [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-01 02:08:51
问题 This question already has answers here : How to concatenate text from multiple rows into a single text string in SQL server? (47 answers) Closed 6 years ago . I'm porting an application I originally wrote to run on Apache using PHP and a MySQL database. One of the queries used the MySQL functions of Concat_WS and Group_Concat to first concatenate a few different columns into one string, and then concatenate all items that were grouped together by the Group_By clause. As an example: ID Name

GROUP_CONCAT() row count when grouping by a text field

一曲冷凌霜 提交于 2019-12-01 01:44:39
问题 DROP TABLE IF EXISTS `table`; CREATE TABLE `table` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; INSERT INTO `table` VALUES ('1', 'Unpacked reserved sir offering bed judgment may and quitting speaking. Is do be improved raptures offering required in replying raillery. Stairs ladies friend by in mutual an no. Mr hence chief he cause. Whole no

Group_Concat in Concat not working with NULL values

江枫思渺然 提交于 2019-12-01 00:47:53
问题 I have a table CREATE TABLE IF NOT EXISTS `dept` ( `did` int(11) NOT NULL, `dname` varchar(50) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `dept` (`did`, `dname`) VALUES (1, 'Hi'), (2, NULL), (3, 'Hello'); Then I have a query select group_concat(concat(did,"','",dname) separator '),(') as Result from dept It is producing result as 1','Hi'),('3','Hello Question: How can I get result from above query as 1','Hi'),('2','NULL'),('3','Hello It is missing the rows which have

mysql group_concat group by on multiple fields

北城余情 提交于 2019-11-30 16:56:40
I have a Table member with member_id , member_name , club_name , region , zone , email as fields. I am using the MySQL group_concat function like SELECT group_concat(distinct m.email SEPARATOR ', ' ) from member m group by m.club_name This is working fine. But I would like to be able to group_concat on other fields without creating additional queries. Is it possible to supply the other fields as parameter? member_id member_name club_name region zone email 1 member1 A 1 1 email1@example.com 2 member2 A 1 1 email2@example.com 3 member3 B 1 1 email3@example.com 4 member4 C 1 2 email4@example.com

How can I use GROUP_CONCAT in Rails?

我只是一个虾纸丫 提交于 2019-11-30 14:33:43
I have the following query which I want to use with ActiveRecord so that it can be translated in native ORACLE based query on production server. Right now I am using SQLITe. select c.name,co.code,GROUP_CONCAT(c.name) AS GroupedName from countries c INNER JOIN continents co on c.continent_code = co.code INNER JOIN event_locations el on el.location_id = c.id group by co.code As long as I know, there's no group_concat equivalent in Rails, but you can use includes to do that: continents = Continents .joins(:countries, :event_locations) .includes(:countries) .group("continents.code") continents

How to concatenate data from one field, in a comma-delimited list, in a many-to-many relationship in MySQL?

最后都变了- 提交于 2019-11-30 11:46:48
I have a many-to-many relationship between People and Departments since one person can be in many departments. People Departments ------ ----------- pID pName deptID deptName 1 James 1 Engineering 2 Mary 2 Research 3 Paul 3 Marketing 4 Communications People_Departments ------------------ pID deptID 1 1 1 2 2 2 2 4 3 1 3 2 3 3 What I want is this: pName deptName James Engineering, Research Mary Research, Communication Paul Engineering, Research, Marketing If I do plain LEFT JOINs on the tables using the SQL below, I will get several rows related to one person: SELECT people.pName, departments

Join one row to multiple rows in another table

99封情书 提交于 2019-11-30 03:06:20
I have a table to entities (lets call them people) and properties (one person can have an arbitrary number of properties). Ex: People Name Age -------- Jane 27 Joe 36 Jim 16 Properties Name Property ----------------- Jane Smart Jane Funny Jane Good-looking Joe Smart Joe Workaholic Jim Funny Jim Young I would like to write an efficient select that would select people based on age and return all or some of their properties. Ex: People older than 26 Name Properties Jane Smart, Funny, Good-looking Joe Smart, Workaholic It's also acceptable to return one of the properties and total property count.

How can I use GROUP_CONCAT in Rails?

半腔热情 提交于 2019-11-29 20:59:44
问题 I have the following query which I want to use with ActiveRecord so that it can be translated in native ORACLE based query on production server. Right now I am using SQLITe. select c.name,co.code,GROUP_CONCAT(c.name) AS GroupedName from countries c INNER JOIN continents co on c.continent_code = co.code INNER JOIN event_locations el on el.location_id = c.id group by co.code 回答1: As long as I know, there's no group_concat equivalent in Rails, but you can use includes to do that: continents =

GROUP_CONCAT comma separator - MySQL

浪尽此生 提交于 2019-11-29 18:58:17
I have a query where I am using GROUP_CONCAT and a custom separator as my results may contain commas: '----' This all works well, however it is still comma separated, so my output is: Result A----,Result B----,Result C---- How can I make it so the output is: Result A----Result B----Result C---- I thought this was the idea of a custom separator! Failing that, can you escape commas in your results, so I can explode in PHP by the GROUP_CONCAT commas? Looks like you're missing the SEPARATOR keyword in the GROUP_CONCAT function. GROUP_CONCAT(artists.artistname SEPARATOR '----') The way you've

How to concatenate data from one field, in a comma-delimited list, in a many-to-many relationship in MySQL?

馋奶兔 提交于 2019-11-29 17:26:56
问题 I have a many-to-many relationship between People and Departments since one person can be in many departments. People Departments ------ ----------- pID pName deptID deptName 1 James 1 Engineering 2 Mary 2 Research 3 Paul 3 Marketing 4 Communications People_Departments ------------------ pID deptID 1 1 1 2 2 2 2 4 3 1 3 2 3 3 What I want is this: pName deptName James Engineering, Research Mary Research, Communication Paul Engineering, Research, Marketing If I do plain LEFT JOINs on the tables