I have a table:
Date | Code
2012-04-01 | 1
2012-04-01 | 0
2012-04-01 | 0
2012-04-01 | 2
2012-04-02 | 4
2012-04-03 | 1
2012-04-03 | 0
2012-04-03 | 0
2012-04-04 | 1
2012-04-04 | 3
2012-04-04 | 4
2012-04-04 | 4
2012-04-04 | 0
Code is predefined from 0-5.
What I would like is a query that Counts by the Code & Date, where each Record is for 1 Date. Each predefined code should be counted in a separate field.
So, the Result should be like:
Date | Code0 | Code1 | Code2 | Code3 | Code4 | Code5
2012-04-01 | 2 | 1 | 1 | 0 | 0 | 0
2012-04-02 | 0 | 0 | 0 | 0 | 1 | 0
2012-04-03 | 2 | 1 | 0 | 0 | 0 | 0
2012-04-04 | 1 | 1 | 0 | 3 | 4 | 0
I would like to do this in the most efficient way possible, the data size would be around 400,000, so some union based queries may hurt the database.
Thanks in advance.