I am a beginner to writing queries and have been racking my brain trying to figure out what the best approach to this is. I have created a temp table and wrote a query to give me the following data this result from the following data.
SELECT Temp.OrderType,Temp.OrderDate,COUNT(*) as prodCount
FROM Temp
GROUP BY Temp.OrderType, Temp.OrderDate
ORDER BY Temp.OrderType;
RESULTS
OrderType OrderDate prodCount
1 2012-06-04 00:00:00.000 1
1 2012-06-06 00:00:00.000 1
2 2012-06-07 00:00:00.000 2
3 2012-06-05 00:00:00.000 1
3 2012-06-06 00:00:00.000 2
3 2012-06-07 00:00:00.000 1
7 2012-06-05 00:00:00.000 1
11 2012-06-07 00:00:00.000 1
How can I go about to get the data to display in this format instead with the count totals going under the date ? Date1 Date2 etc, are 6/04, 6/05, 6/06, 6/07. Any help or guidance is appreciated. Thanks you!
OrderType Date1 Date2 Date3 Date4
1 1 1
2 2
3 1 2 1
4
7 1
11 1
SAMPLE DATA
OrderDate OrderType
2012-06-06 00:00:00.000 1
2012-06-04 00:00:00.000 1
2012-06-05 00:00:00.000 7
2012-06-05 00:00:00.000 3
2012-06-06 00:00:00.000 3
2012-06-06 00:00:00.000 3
2012-06-07 00:00:00.000 3
2012-06-07 00:00:00.000 2
2012-06-07 00:00:00.000 2
2012-06-07 00:00:00.000 3
2012-06-07 00:00:00.000 11
PIVOTthat greatly simplifies this kind of queries.