[英]Merge three mysql entries to one entry
I have 3 or 4 entries with the same name of a person an different other entries. 我有3或4个条目,一个人的名字相同,其他条目不同。
A B C
---- ---- -----------
a 01 XXX
a 02 XYZ
a 03 ABC
How can I merge them by selecting the a which is always the same in A to a structure like this: 我该如何通过选择a来合并它们,所以在A中始终相同,所以像这样的结构:
A B C D E F G
--- --- --- --- --- --- ---
a 01 02 03 XXX XYZ ABC
Hope you can help me getting this. 希望你能帮助我。
Alternative Solution 替代解决方案
If you have variable number of entries for different users then use GROUP_CONCAT FUNCTION. 如果不同用户的条目数可变,则使用GROUP_CONCAT FUNCTION。 It is easier way (with some processing in php) than to make dynamic number of columns in sql.
比在sql中动态创建列数更简单(在php中进行一些处理)。
SELECT A,GROUP_CONCAT(B) B, GROUP_CONCAT(C) C
FROM TABLE
GROUP BY A;
The result will be like:- ABC 结果将是:-ABC
--- --- --- a 01,02,03 XXX,XYZ,ABC ----a 01,02,03 XXX,XYZ,ABC
You can further process it in php code to get column separated. 您可以在php代码中进一步处理它,以使列分开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.