0

我有一张表,其中包含 stamp_type 和 amount 列,如下所示

                          stamp_type                          | amount
--------------------------------------------------------------+--------
 GENERAL STAMP                                                |  11000
 GENERAL STAMP                                                |  25000
 COURT FEE STAMP                                              |   9800
 SPECIAL ADHESIVE                                             | 721000
 GENERAL STAMP                                                | 125000
 COURT FEE STAMP                                              |  21000

现在我想显示如下:

    stamp_type                                                    | amount
    GENERAL STAMP                                                   161000
    COURT FEE STAMP                                                 30800
    SPECIAL ADHESIVE                                                721000

TOTAL:912800

我无法显示唯一值。任何人都可以给我建议的查询。我尝试使用 Distinct 但效果很好。

4

2 回答 2

2
select * from 
(
select  0 as srt, stamp_type, sum(amount) as SumAmount from t group by stamp_type
union 
select 1 as srt, 'Total' as stamp_type, sum(amount) as SumAmount from t 
) b order by srt
于 2012-12-13T07:09:44.123 回答
1

试试这个代码::

 select stamp_type, sum(amount) amount
    from tbl
    group by stamp_type
 union
 select 'Total:' stamp_type,sum(amount) amount
 from tbl;
于 2012-12-13T07:06:06.397 回答