-- MySQL语法 8.0.16
SELECT
品牌描述
,销售额
,sum(销售额) over(order by 销售额 desc) as 逐层累计值
,sum(销售额) over() as 总累计值
,sum(销售额) over(order by 销售额 desc)/sum(销售额) over() as 累计占比
FROM
(
select
b.品牌描述
,sum(a.销售额) as 销售额
from
SalesDetails a
INNER JOIN BrandDimension b ON a.品牌编号 = b.品牌编号
GROUP BY
b.品牌描述
) m
——————————————————————