简体   繁体   English

mysql GROUP_CONCAT标签来自一列,结果来自另一列

[英]mysql GROUP_CONCAT label results from one column with value from another

I have a table that lists urls to product photos. 我有一张桌子,上面列出了产​​品照片的网址。 In the table the photos are listed multiple times (once for the various resizes that have been done during the upload). 在表格中,照片被列出了多次(一次用于上传期间进行的各种尺寸调整)。 The table has three columns of interest: 该表包含三个感兴趣的列:

photoFlag photoName objectID

Using GROUP_CONCAT i can get all the photo urls for each product but then i lose the photoFlag tag. 使用GROUP_CONCAT,我可以获得每个产品的所有照片网址,但是随后我丢失了photoFlag标签。 the results come as 结果来了

other_columns photoName1,photoName2,photoName3,etc

I would like them to come like: 我希望他们来像:

other_columns photoFlag1*photoName1,photoFlag2*photoName2,photoFlag3*photoName3,etc

So that when processing the result set I can easily pick the best photo options from the list. 这样,在处理结果集时,我可以轻松地从列表中选择最佳的照片选项。

Is this even possible? 这有可能吗?

SELECT other_columns, GROUP_CONCAT(CONCAT_WS('*', photoFlag, photoName))
    FROM YourTable
    GROUP BY SomeColumn;

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

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