[英]How to add the total row after the blank line?
How to add the total row at the end with all the totals?如何在最后添加总行和所有总数? When I run the query, I want to see the row after the blank line, with totals.
当我运行查询时,我想查看空白行之后的行,以及总计。 Please look at the table below.
请看下表。 If the column is not summable then that should be blank as well.
如果该列不可求和,则该列也应为空白。
select
t.Business_Unit_Description,
billable_trades,
@rate rate,
billable_trades * @rate as charge,
isnull(c.comm_adjustments, 0) as commission_adjustments,
0.3 commission_adj_rate,
isnull(c.comm_adjustments, 0) * 0.3 * -1 as credit,
((billable_trades * @rate) + (isnull(c.comm_adjustments, 0) * 0.3 * -1)) as total
from
(
select Business_Unit_Description, sum(billable_trades) as billable_trades
from #cte_combined
group by Business_Unit_Description
) t
left outer join #cte_comm_adj c on c.Business_Unit_Description =
t.Business_Unit_Description
order by t.Business_Unit_Description
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.