I have the following table.
File Type Date Opened
------------- ---------------
jpg 01-03-2010
gif 01-02-2010
png 18-02-2010
png 06-01-2010
jpg 02-03-2010
gif 25-02-2010
gif 30-01-2010
png 12-01-2010
jpg 19-02-2010
and would like to count all the different file types that were opened in January, February and March to produce this result.
File Type Opened in Jan Opened in Feb Opened in Mar
--------- ------------- ------------- -------------
jpg 0 1 2
gif 1 2 0
png 2 1 0
I have the following sql
SELECT [File Type], COUNT([File Type]) As [Opened in January] from Files
Where [Date Opened] between '01-01-2010' and '31-01-2010'
Group BY [File Type]
How do I extend my query to add a further two columns for Feb and March?
Also, How do I bring back the File Type when the Count is 0.
The above query does not bring back the jpg filetype but I still want all file types returned even if the count is 0.
I have trying left joins, sub queries etc but can't get my head around it.
Hope someone can help.
File Type Date Opened
------------- ---------------
jpg 01-03-2010
gif 01-02-2010
png 18-02-2010
png 06-01-2010
jpg 02-03-2010
gif 25-02-2010
gif 30-01-2010
png 12-01-2010
jpg 19-02-2010
and would like to count all the different file types that were opened in January, February and March to produce this result.
File Type Opened in Jan Opened in Feb Opened in Mar
--------- ------------- ------------- -------------
jpg 0 1 2
gif 1 2 0
png 2 1 0
I have the following sql
SELECT [File Type], COUNT([File Type]) As [Opened in January] from Files
Where [Date Opened] between '01-01-2010' and '31-01-2010'
Group BY [File Type]
How do I extend my query to add a further two columns for Feb and March?
Also, How do I bring back the File Type when the Count is 0.
The above query does not bring back the jpg filetype but I still want all file types returned even if the count is 0.
I have trying left joins, sub queries etc but can't get my head around it.
Hope someone can help.