简体   繁体   English

MariaDB GROUP_CONCAT只返回一个值

[英]MariaDB GROUP_CONCAT only returns one value

I am experiencing a strange issue with the GROUP_CONCAT function in my instance, where using it to group together integers works just fine, but applying it to a varchar doesn't work at all. 我在我的实例中遇到了GROUP_CONCAT函数的一个奇怪问题,其中使用它将整数组合在一起工作得很好,但将它应用于varchar根本不起作用。

The data is along the lines of: 数据如下:

CUSTOMERID  LOCATIONNAME    PRODUCTID   UNITS   ID  PRODUCTNAME
1           Location            65       100    1   Product 65
1           Location            66       100    2   Product 66
1           Location            67       100    3   Product 67
1           Location            68       100    4   Product 68
1           Location            68       100    5   Product 68

When I run: SELECT GROUP_CONCAT(DISTINCT lm.ProductID) as Brand FROM locationMap lm WHERE (lm.CustomerID = 1); 当我运行时: SELECT GROUP_CONCAT(DISTINCT lm.ProductID) as Brand FROM locationMap lm WHERE (lm.CustomerID = 1);

It returns 65, 66, 67, 68 and works properly. 它返回65,66,67,68并正常工作。

When I run: SELECT GROUP_CONCAT(DISTINCT lm.ProductName) as Brand FROM locationMap lm WHERE (lm.CustomerID = 1); 当我运行时: SELECT GROUP_CONCAT(DISTINCT lm.ProductName) as Brand FROM locationMap lm WHERE (lm.CustomerID = 1);

It returns only the first item (Product 65). 它仅返回第一个项目(产品65)。

I set up an SQL Fiddle ( http://www.sqlfiddle.com/#!2/2392f/3 ) to test it out, and everything functions properly there. 我设置了一个SQL小提琴( http://www.sqlfiddle.com/#!2/2392f/3 )来测试它,一切都在那里正常运行。 Can anyone offer a suggestion for what might be wrong in my environment that would cause this? 任何人都可以提出我的环境中可能导致错误的建议吗? I'm running 5.5.30-MariaDB-30.1 我正在运行5.5.30-MariaDB-30.1

Verified that upgrading the server from 5.5.30-MariaDB-30.1 to 5.5.38-MariaDB-35.2 has resolved this issue. 已验证将服务器从5.5.30-MariaDB-30.1升级到5.5.38-MariaDB-35.2已解决此问题。 Thanks to everyone for their suggestions. 感谢大家的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM