[Solved] How to add the total row after the blank line?


Assume that you table contains information about Company, Charge, Commission and you want to get total per each company and also per each of its column.
As you didn’t provide any table schemas or your data sample, I created a table, populated with data from your question.

I’d suggest the next query:

create table test
(
    Company varchar(20) not null,
    Charge int not null,
    Commission int not null
)

insert into test
values 
('A', 50, 20),
('B', 23, 10),
('C', 80, 23),
('D', 60, 12)

select Company, Charge, Commission, SUM(Charge + Commission) OVER (PARTITION BY Company ORDER BY Company ASC) as total 
from test
union all
select 'Total', SUM(Charge), SUM(Commission), SUM(Charge + Commission)
from test

0

solved How to add the total row after the blank line?