Help with PIVOT?

  • Hi,

    Been a while since I have visited here. I have got a query which gives me a result set shown below.

    SEQ GROUPNAME DATADATE DATADAY TOTALCOUNT

    1 Mail In 2010-08-16 MON 540

    1 Mail In 2010-08-17 TUE 576

    1 Mail In 2010-08-18 WED 480

    1 Mail In 2010-08-19 THU 198

    1 Mail In 2010-08-20 FRI 510

    1 Mail In 2010-09-20 TODAY 265

    2 Mail Out 2010-08-16 MON 348

    2 Mail Out 2010-08-17 TUE 282

    2 Mail Out 2010-08-18 WED 462

    2 Mail Out 2010-08-19 THU 384

    2 Mail Out 2010-08-20 FRI 72

    2 Mail Out 2010-09-20 TODAY 307

    How do I PIVOT it to get a final result set shown below?

    GROUPNAME MON TUE WED THU FRI TODAY TOTAL (ex. TODAY) AVG

    Mail In 540 576 480 198 510 265 2304 460.8

    Mail Out 348 282 462 384 72 307 1548 309.6

    Any help would be appreciated. Just to clarify, "Mail In" and "Mail Out" are just examples, there are more than 10 categories but I didn't feel it was necessary to post all categories and thus making this too long to use.


    Kindest Regards,

    WRACK
    CodeLake

  • APOLOGIES ABOUT THE DOUBLE POST... THE WEB BROWSER DID IT!


    Kindest Regards,

    WRACK
    CodeLake

  • No replies to this thread please. Direct replies to:http://qa.sqlservercentral.com/Forums/Topic989110-392-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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