· 7 years ago · Sep 04, 2018, 02:40 PM
1mysql query grouping
2sku type color quantity
3---------------------------
41 type1 blue 5
51 type1 blue 2
62 type1 blue 5
71 type1 green 5
8
9sku type color quantity
10---------------------------
111 type1 blue 7
122 type1 blue 5
131 type1 green 5
14
15SELECT sku,type,color,
16 SUM(quantity)
17 FROM table
18GROUP BY sku,type,color
19
20SELECT sku, type, color, sum(quantity)
21FROM theTable
22GROUP BY sku, type, color
23
24CREATE TEMPORARY TABLE IF NOT EXISTS tmpTable LIKE dataTable
25
26DELETE FROM tmpTable
27
28Insert into tmpTable
29select sku,type,color,sum(quantity) from dataTable
30group by sku,type,color
31
32DELETE FROM dataTable
33
34INSERT INTO dataTable
35SELECT * FROM tmpTable