Mysql GROUP_CONCAT 基于计数相乘

Mysql GROUP_CONCAT multiplies based on count

我正在尝试进行 mysql 查询,其中 GROUP_CONCAT 是 table 'shop_previews' 中的所有字符串。 但是,当 运行 以下查询时,它会根据 "timesBought".

的数量重复它
select 
    `shop_items`.*, 
     group_concat(shop_previews.image) as images, 
     count(`shop_histories`.`shopId`) as `timesBought` 
from `shop_items`
left join `shop_previews` on `shop_previews`.`shopId` = `shop_items`.`id`
left join `shop_histories` on `shop_items`.`id` = `shop_histories`.`shopId`
group by `shop_items`.`id` 
order by `timesBought` desc

因此,如果 timesBought 等于二,并且 shop_previews.image 只有一个结果,它会将那个条目与自身连接起来,结果类似于

https://example.com/example.png,https://example.com/example.png

GROUP_CONCAT()支持DISTINCT:

GROUP_CONCAT(DISTINCT shop_previews.image) as images