给出以下内容 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) 我需要类似于这两个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)
这可能吗?
我有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值会更好,但我只是想知道我是否可以用某种方式填充这个列.
假设我有一张桌子:学生
______________________________________________________
|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) 我搜索了很多,但没有找到解决问题的正确方法.
我想做什么?
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()这样的函数,但这不起作用.
我有一个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子句中的最低值.
我有一个规范化的数据库,我正在尝试使用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) 我有以下查询,我想与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) 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) group-concat ×10
mysql ×7
sql ×4
join ×2
dataframe ×1
duplicates ×1
group-by ×1
informix ×1
left-join ×1
one-to-many ×1
oracle ×1
pandas ×1
php ×1
python ×1