Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to add Aggregate column with Pivot Expand / Collapse
Author
Message
Posted Tuesday, June 25, 2013 1:17 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 1:22 AM
Points: 171, Visits: 449
Hi All,

I am using Pivot in my query.My problem is that i want to add Average column of Pivoted columns.
Please give an idea how to do that?


eg. if my Pivoted columns are - [1],[2],[3],[4],[5] then i need to display one more column as sum of avg of all this 5 columns like below.

Select [1],[2],[3],[4],[5],(AVG([1])+AVG([2])+AVG([3])+AVG([4])+AVG([5])) as Avg from #temp.

Thanks
Abhas.
Post #1467007
Posted Tuesday, June 25, 2013 6:52 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, April 10, 2014 5:09 AM
Points: 2,567, Visits: 4,654
I am not really sure about the output you are expecting
It would help if you can provide DDL of the table involved with some sample data and the expected results based on the sample data
Please check the link in my signature if you are not sure about how to provide this
I am sure you will get reply in a matter of few minutes if you provide all this



Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1467114
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse