【发布时间】:2020-05-23 00:07:27
【问题描述】:
我正在尝试对 GROUP_CONCAT 表“shop_previews”中的所有字符串进行 mysql 查询。 但是,在运行以下查询时,它会根据“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 等于 2,并且 shop_previews.image 中只有一个结果,它将将该条目与自身连接起来,从而产生类似
https://example.com/example.png,https://example.com/example.png
【问题讨论】:
标签: mysql sql group-by group-concat