You're really looking for 2 sets of results here. The individual row output and the group by output require 2 separate queries.
You could
SELECT code, amount
FROM table1
ORDER BY code
for the individual amounts, and
SELECT code, sum(amount)
FROM table1
GROUP BY code
for the sums.
Personally I'd rather avoid making a second query. Just use the first query and do the summing/formatting from within my Java code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…