--example in sql server 2000

--prepare data
drop table #t

create table #t
(
        col1 char(255),
        col2 char(255),
        je numeric(19,2)
)
insert into #t select 'K55', 'K5506', 1234
insert into #t select 'K55', 'K5507', 4321
insert into #t select 'K56', 'K5601', 3333
insert into #t select 'K56', 'K5602', 6666

--report
select
        case
                when (grouping(col1)=1) then '总计'
                else
                case
                        when (grouping (col2) = 1 ) then
isnull(rtrim(col1),'')
                        else space(1*4)+isnull(rtrim(col2),'')
                end
        end as xm,

        sum(je)

        from #t
        group by col1, col2 with rollup
        order by grouping(col1) desc, col1, grouping(col2) desc, col2

--result
总计      15554.00
K55     5555.00
    K5506       1234.00
    K5507       4321.00
K56     9999.00
    K5601       3333.00
    K5602       6666.00

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to