标签: group-concat

pandas中的新列 - 通过应用列表groupby将数组添加到数据框中

给出以下内容 df

  Id other  concat
0  A     z       1
1  A     y       2
2  B     x       3
3  B     w       4
4  B     v       5
5  B     u       6
Run Code Online (Sandbox Code Playgroud)

我希望结果包含new带有分组值的列作为列表

  Id other  concat           new
0  A     z       1        [1, 2]
1  A     y       2        [1, 2]
2  B     x       3  [3, 4, 5, 6]
3  B     w       4  [3, 4, 5, 6]
4  B     v       5  [3, 4, 5, 6]
5  B     u       6  [3, 4, 5, 6] …
Run Code Online (Sandbox Code Playgroud)

python group-concat dataframe pandas pandas-groupby

7
推荐指数
1
解决办法
777
查看次数

显示一对多关系为2列 - 1个唯一行(ID和逗号分隔列表)

我需要类似于这两个SO问题,但使用Informix SQL语法.

我的数据如下:

id     codes

63592  PELL
58640  SUBL
58640  USBL
73571  PELL
73571  USBL
73571  SUBL
Run Code Online (Sandbox Code Playgroud)

我希望看到它像这样回来:

id     codes 

63592  PELL
58640  SUBL, USBL
73571  PELL, USBL, SUBL
Run Code Online (Sandbox Code Playgroud)

另请参见Informix中的group_concat().

sql informix concatenation one-to-many group-concat

6
推荐指数
1
解决办法
8266
查看次数

MySQL:使用JOIN和GROUP_CONCAT更新

这可能吗?

我有2个表,客户和订单.现在,我想在客户中填写该客户的所有订单ID(以逗号分隔).

我试过这样的东西,但它不起作用:

UPDATE customers AS c
LEFT JOIN orders AS o ON o.customerid=c.customerid
SET c.orders = GROUP_CONCAT(DISTINCT o.orderid)
Run Code Online (Sandbox Code Playgroud)

我得到'无效使用群组功能'.

PS.我知道总是在SELECT/JOIN中动态获取GROUP_CONCAT值会更好,但我只是想知道我是否可以用某种方式填充这个列.

mysql join group-concat mysql-error-1111

6
推荐指数
3
解决办法
8058
查看次数

如何在Zend Framework中使用GROUP_CONCAT?

假设我有一张桌子:学生

______________________________________________________
|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 …
Run Code Online (Sandbox Code Playgroud)

php mysql zend-framework group-concat zend-db-select

6
推荐指数
1
解决办法
5996
查看次数

SQL GROUP_CONCAT分成不同的列

我搜索了很多,但没有找到解决问题的正确方法.

我想做什么?

MySQL中有2个表: - Country - Currency(我通过CountryCurrency将它们连接在一起 - >由于多对多关系)

请参阅此示例以获取一个工作示例:http://sqlfiddle.com/#!2/317d3/8/0

我想使用连接将两个表链接在一起,但我希望每个国家只显示一行(某些国家/地区有多种货币,因此这是第一个问题).

我找到了group_concat函数:

SELECT country.Name, country.ISOCode_2, group_concat(currency.name) AS currency
FROM country
INNER JOIN countryCurrency ON country.country_id = countryCurrency.country_id
INNER JOIN currency ON currency.currency_id = countryCurrency.currency_id
GROUP BY country.name
Run Code Online (Sandbox Code Playgroud)

这有以下结果:

NAME            ISOCODE_2   CURRENCY

Afghanistan AF          Afghani
Åland Islands   AX          Euro
Albania         AL          Lek
Algeria         DZ          Algerian Dinar
American Samoa  AS          US Dollar,Kwanza,East Caribbean Dollar
Run Code Online (Sandbox Code Playgroud)

但我现在想要的是将货币分成不同的列(货币1,货币2,......).我已经尝试过像MAKE_SET()这样的函数,但这不起作用.

mysql sql group-concat

6
推荐指数
1
解决办法
5755
查看次数

在IN Clause Mysql中使用GROUP_CONCAT结果

我有一个aq查询,它返回逗号拼写的整数,如

select GROUP_CONCAT(ids) from table2
Run Code Online (Sandbox Code Playgroud)

现在我想在另一个查询中使用该结果

select * from table1 where column in (select GROUP_CONCAT(ids) from table2)
Run Code Online (Sandbox Code Playgroud)

在这种情况下,它只考虑IN子句中的最低值.

mysql group-concat

6
推荐指数
2
解决办法
5625
查看次数

MySQL - GROUP_CONCAT返回重复数据,不能使用DISTINCT

我有一个规范化的数据库,我正在尝试使用JOIN和GROUP_CONCAT从多个表返回数据.

问题:行与GROUP_CONCAT重复.我不能使用DISTINCT,因为某些数据(成分mfr)确实需要重复.

这是我当前的查询和db结构(SQL Fiddle):

SELECT recipe.*, 
GROUP_CONCAT(recipe_detail.ingredient_id) AS iid,  
GROUP_CONCAT(ingredient.name) AS iname, 
GROUP_CONCAT(ingredient_mfr.abbr) AS mabbr, 
GROUP_CONCAT(recipe_tag.name) AS tag
FROM  recipe
LEFT JOIN recipe_detail
    ON recipe.id = recipe_detail.recipe_id
LEFT JOIN ingredient
    ON recipe_detail.ingredient_id = ingredient.id
LEFT JOIN ingredient_mfr
    ON ingredient.mfr_id = ingredient_mfr.id
LEFT JOIN recipe_tagmap
    ON recipe.id = recipe_tagmap.recipe_id
LEFT JOIN recipe_tag
    ON recipe_tagmap.tag_id = recipe_tag.id
WHERE recipe.user_id = 1
GROUP BY recipe.id

recipe
+------------+------------+-----------+
|    id      |    name    |  user_id  |
+============+============+===========+
|     1      |  Test123   |     1 …
Run Code Online (Sandbox Code Playgroud)

mysql sql left-join duplicates group-concat

6
推荐指数
1
解决办法
2307
查看次数

如何在Rails中使用GROUP_CONCAT?

我有以下查询,我想与ActiveRecord一起使用,以便它可以在生产服务器上的本机ORACLE查询中进行翻译.现在我正在使用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
Run Code Online (Sandbox Code Playgroud)

sql oracle ruby-on-rails group-concat

6
推荐指数
1
解决办法
4173
查看次数

在MySQL中有多个连接的group_concat

数据库架构

create table `questions` (
  `id` int not null auto_increment,
  `title` varchar(45) not null,
  primary key (`id`));

create table `tags` (
  `id` int not null auto_increment,
  `question_id` int not null,
  `name` varchar(45) not null,
  primary key (`id`));

create table `comments` (
  `id` int not null auto_increment,
  `question_id` int not null,
  `body` varchar(45) not null,
  primary key (`id`));

insert into questions (title) values
("title1"), ("title2"), ("title3");

insert into tags (question_id, name) values
(1, "javascript"), (1, "php"), (1, "c#"), (2, "mysql"), (2, …
Run Code Online (Sandbox Code Playgroud)

mysql join group-concat

6
推荐指数
1
解决办法
1175
查看次数

根据MySql中的两列删除重复记录

我想删除多余的重复记录

即在显示的图像中有两条记录corporate_id = 5category_id = 19,如何删除任何重复的行(这corporate_sed_id是主键)

在此处输入图片说明

mysql group-by group-concat

6
推荐指数
1
解决办法
3987
查看次数