• Probably not the best way, but seems to work

    SELECT DISTINCT

    Grp_A, Grp_B, Grp_C,

    SUM(Val_A) OVER(PARTITION BY Grp_A, Grp_B, Grp_C) AS GrpBy_ABC,

    SUM(Val_B) OVER(PARTITION BY Grp_A, Grp_B) AS GrpBy_AB

    FROM #a

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537