你好我必须加入两个查询才能形成结果集: -
第一
SELECT
orderId,
GROUP_CONCAT(DISTINCT(categoryId) ORDER BY orderId SEPARATOR ', ') as catId
FROM
ecart_product
INNER JOIN ecart_orderdetail
WHERE
ecart_orderdetail.productId = ecart_product.id
group by orderId
这给了我
orderId catId 167 59, 2 168 2 169 2 170 2 171 2 172 48, 2 173 2 174 2
第二名:
select * from ecart_orders
两个orderId中的通常如何才能加入?
答案 0 :(得分:2)
假设orderId
表格中ecart_orders
为PK,且productId
列为{。}
你可以试试这个:
SELECT
orderId,
GROUP_CONCAT(DISTINCT(categoryId) ORDER BY orderId SEPARATOR ', ') as catId ,
ecart_orders.*
FROM
ecart_product
INNER JOIN ecart_orderdetail
ON ecart_orderdetail.productId = ecart_product.id
INNER JOIN ecart_orders
ON ecart_orders.productId = ecart_product.id
group by orderId
答案 1 :(得分:0)
同时我也解决了它
select * from ecart_orders Inner join(
SELECT
orderId,
GROUP_CONCAT(DISTINCT(categoryId) ORDER BY orderId SEPARATOR ', ') as catId
FROM `ecart_product` INNER JOIN ecart_orderdetail
WHERE ecart_orderdetail.productId = ecart_product.id group by orderId) as c
on ecart_orders.id=c.orderId