I have a table that currently is a long list of devices and information about when they were sold. I need to take the table which would look something like this:
Item | Time Sold
--------------------
A 05/2010
B 04/2010
C 03/2010
A 04/2010
A 05/2010
And then have a table with the item as the first column, with the count of the dates being the column headers, like below:
Item | Count_03/2010 | Count_04/2010 | Count_05/2010
-------------------------------------------------------------
A | 0 | 1 | 2
B | 0 | 1 | 0
C | 1 | 0 | 0
Is there a simple way of doing this? I know in other languages there is a single command to do it, was wondering if SQL had one.
EDIT
My problem is that there is more than one table, and in some tables the months may be different than in other tables. Is there anyway to write a script that will apply to them all, by getting the variables listed and then using those to create the columns in the code? I could write one if I knew the months would always be the same, but since they are variable, is there a way of doing this.
Thanks!