How to add Aggregate column with Pivot

  • 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.

  • 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/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply