• Probably a more efficient way, but this is the idea:

    ; WITH MyCTE (acc_no, c_name, cnt)

    AS

    ( SELECT acc_no

    , c_name

    , COUNT(c_name)

    FROM #testing a

    GROUP BY acc_no

    , c_name

    )

    SELECT

    t.acc_no

    , c.c_name

    , number_sum = SUM( t.number)

    , r_value_sum = SUM( t.R_Value)

    FROM #TESTING t

    INNER JOIN mycte c

    ON t.acc_no = c.acc_no

    WHERE c.cnt = (SELECT MAX(d.cnt)

    FROM MyCTE d

    WHERE d.acc_no = c.acc_no

    )

    GROUP BY t.acc_no

    , c.c_name

    You need to count and get the max count of the names, by account and then join with the sum.