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
Posted Tuesday, June 25, 2013 1:17 AM


Group: General Forum Members
Last Login: Friday, August 22, 2014 5:49 AM
Points: 195, Visits: 497
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.

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



Group: General Forum Members
Last Login: Friday, August 22, 2014 12:13 AM
Points: 2,631, Visits: 4,723
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
Post #1467114
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse