Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
noyellatmonkeys
Starting Member
15 Posts |
Posted - 2009-12-03 : 16:07:55
|
| Any Help would be extremely usefull!!!I have a table that looks like thisid page traffic month year1 home 1000 11 092 books 800 11 093 home 1200 10 094 books 750 10 09what i want is to be able to see the info as follows______10 09 | 11 09home 1200 1000books 750 800Any suggestions? |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-12-03 : 16:09:53
|
quote: Originally posted by noyellatmonkeysid page traffic month year1 home 1000 11 092 books 800 11 093 home 1200 10 094 books 750 10 09 what i want is to be able to see the info as follows10 09 | 11 09home 1200 1000books 750 800 Any suggestions?
What Version of SQL Server are you on?We need to look up PIVOT probably....Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
noyellatmonkeys
Starting Member
15 Posts |
Posted - 2009-12-03 : 16:59:19
|
| sql server express 2008 |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-12-04 : 00:36:43
|
| Hi try this,DECLARE @temp TABLE (id INT, page VARCHAR(32),traffic INT,months VARCHAR(32), years VARCHAR(32) )INSERT INTO @temp SELECT 1, 'home', 1000, 11, 09INSERT INTO @temp SELECT 2, 'books', 800, 11, 09INSERT INTO @temp SELECT 3, 'home', 1200, 10, 09INSERT INTO @temp SELECT 4, 'books', 750, 10, 09SELECT page, MAX([10_9]) AS [10_9],MAX([11_9]) AS [11_9]FROM ( SELECT id,page,traffic,months+'_'+years AS monthsss FROM @temp ) tPIVOT ( MAX(traffic) FOR monthsss IN ( [10_9],[11_9] ))pGROUP BY page |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|