goods
id order_id name number
1 123 卡丁车 1
2 123 玩具车 1
3 123 积木车 1
4 124 卡丁车 2
order
order_id order_num
123 201605291
124 201605292
SELECT o.order_id,g.* FROM `goods` AS g LEFT JOIN `order` AS o ON g.order_id = o.order_id ORDER BY g.id DESC
就是相同产品的,数量相加,上面这句SQL语句要怎么改才能变成这样
id order_id name number
1 123 卡丁车 3
2 123 玩具车 1
3 123 积木车 1
id order_id name number
1 123 卡丁车 1
2 123 玩具车 1
3 123 积木车 1
4 124 卡丁车 2
order
order_id order_num
123 201605291
124 201605292
SELECT o.order_id,g.* FROM `goods` AS g LEFT JOIN `order` AS o ON g.order_id = o.order_id ORDER BY g.id DESC
就是相同产品的,数量相加,上面这句SQL语句要怎么改才能变成这样
id order_id name number
1 123 卡丁车 3
2 123 玩具车 1
3 123 积木车 1
解决方案
40
select id ,order_id , name, sum(number)
from `goods`
group by name
from `goods`
group by name