With a MySQL query, how can I take a table like in Example A:
Example A
+------+---------------+----------+
| id | value | class |
+------+---------------+----------+
| 1 | 33.00 | total |
| 1 | 12.00 | shipping |
| 2 | 45.00 | total |
| 2 | 15.00 | shipping |
+------+---------------+----------+
And create a view like Example B?
Example B
+------+---------------+---------------+
| id | value_total | value_shipping|
+------+---------------+---------------+
| 1 | 33.00 | 12.00 |
| 2 | 45.00 | 15.00 |
+------+---------------+---------------+
You can simply use
SUM()
function for that:See this SQLFiddle
If you have unknown number of class then try this Dynamic query
Output:
See this SQLFiddle
try this
DEMO HERE