我有两张表:产品& 销售
产品
id- productname - grp
11 bmwblue bmw
12 bmwwhite bmw
13 audiblack audi
14 audiwhite audi
销售
id productid amount
1 11 2
2 12 1
x 13 5
x 14 3
我该如何表现;
听觉8,宝马3?答案 0 :(得分:0)
SELECT grp,
sum(amount) AS total_grp_amount
FROM products AS p
JOIN sales AS s ON p.id = s.product_id
GROUP BY grp
我猜你正在寻找这个。