You don't say any particular dialect of SQL
SELECT LEFT(Acct#,3), SUM(Amount)
FROM yourTable
GROUP BY LEFT(Acct#,3)
Or to handle arbitrary length account numbers
SELECT
CASE
WHEN Acct# LIKE '%T'
THEN SUBSTRING(Acct#,1,LEN(@Acct)-1)
ELSE Acct#
END,
SUM(Amount)
FROM yourTable
GROUP BY
CASE
WHEN Acct# LIKE '%T'
THEN SUBSTRING(Acct#,1,LEN(@Acct)-1)
ELSE Acct#
END
Or a more generic approach that will handle arbitrary mappings might be to construct a mapping table that you can then join on. There is quite a lot of missing information here as to the rules that need to be applied!
SELECT d.b, SUM(yt.Amount)
FROM yourTable yt
join (
SELECT '123' as a, '123' as b UNION ALL
SELECT '123T' as a, '123' as b UNION ALL
SELECT '124' as a, '124' as b UNION ALL
SELECT '124T' as a, '124' as b UNION ALL
SELECT '125' as a, '125' as b UNION ALL
SELECT '125T' as a, '125' as b
) d ON d.a = yt.Acct#
GROUP BY d.b