I have a MySQL table whose structure and data looks something like this:
name | date | type | value -----+------------+-------+------ foo | 2013-01-01 | blue | 4 foo | 2013-01-02 | green | 1 foo | 2013-01-01 | blue | 9 foo | 2013-01-02 | green | 5 bar | 2013-01-01 | blue | 10 bar | 2013-01-02 | green | 4 bar | 2013-01-01 | blue | 6 bar | 2013-01-02 | green | 2 meow | 2013-01-01 | blue | 5 meow | 2013-01-02 | green | 6 meow | 2013-01-01 | blue | 4 meow | 2013-01-02 | green | 4
I'm trying to construct a query that will produce this output:
name | blue | green -----+------+------ foo | 13 | 6 bar | 16 | 6 meow | 9 | 10
The name column is maintained. The blue and green columns of the output are generated based on the values of the type table column. The values of those two columns are the accumulated value of the value table column for all dates. I hope that made sense.
This is a bit out of my league when it comes to MySQL so I have no idea where to start. Is this possible using MySQL, and if so, how? For instance, how does one create output columns based on the values of a single table column?
Edit: I should specify; there is no need for this to be a single query. As long as it can be done without involving any other technologies than MySQL then I have no constraints regarding subqueries, multiple queries, views etc.