Can SQL output monthly results horizontally?
Posted on 2006-10-29
Hi, this a VERY long shot but here's what I'm trying to do:
I have a table which records visits. A visit is recorded simply by writing the date (without the time) to the table.
What I need is to count the hits by year and by month and display them. I'm trying to get it to work in MS Access first.
I can display the results VERTICALLY using:
SELECT Year([VisitDate]) AS [The Year], Month([VisitDate]) AS [The Month], Count(*) AS [Total Number]
GROUP BY Year([VisitDate]), Month([VisitDate])
ORDER BY Year([VisitDate]), Month([VisitDate]);
My question is...can it be done horizontally so that the output looks like:
Year Jan Feb Mar Apr etc
2005 10 15 20 25
2006 15 20 25 30
Thanks for reading this