oracle
with T as (select GId, gname, gcolour, gwithin, gsize, sum(gnumber) gnumber from t_goods group by GId, gname, gcolour, gwithin, gsize union all select gid, gname, null, null, '小计', sum(gnumber) from t_goods group by gid, gname) select rownum seq, decode(rn, 1, gid) gid, decode(rn, 1, gname) gname, gcolour, gwithin, gsize, gnumber from (select t.*, row_number() over(partition by gid order by gnumber) rn from t);