select
客户名称 = case when 客户名称 is null then '总计'
when 产品名称 is null then 客户名称+'合计'
when 规格 is null then 客户名称+产品名称+'小计'
else 客户名称
end
产品名称 ,
规格 ,
金额 = sum(金额)
from
表
group by
客户名称,产品名称,规格 with rollup
客户名称 = case when 客户名称 is null then '总计'
when 产品名称 is null then 客户名称+'合计'
when 规格 is null then 客户名称+产品名称+'小计'
else 客户名称
end
产品名称 ,
规格 ,
金额 = sum(金额)
from
表
group by
客户名称,产品名称,规格 with rollup
客户名称 = case when 客户名称 is null then '总计'
when 产品名称 is null then 客户名称+'合计'
when 规格 is null then 客户名称+产品名称+'小计'
else 客户名称
end,
产品名称,
规格,
金额=sum(金额)
from
表
group by
客户名称,产品名称,规格 with rollup