怎么不好使 得说说呗
with sale as(
select 'a' [种类],10 [已售出],17.5 [售价]
UNION ALL
select 'a' [种类],12 [售出],17.5 [售价]
UNION ALL
select 'a' [种类],13 [售出],17.5 [售价]
UNION ALL
select 'B' [种类],14 [售出],17.5 [售价]
UNION ALL
select 'B' [种类],15 [售出],17.5 [售价]
UNION ALL
select 'C' [种类],16 [售出],17.5 [售价]
UNION ALL
select 'C' [种类],17 [售出],17.5 [售价]
UNION ALL
select 'D' [种类],18 [售出],17.5 [售价]
UNION ALL
select 'D' [种类],19 [售出],17.5 [售价]
)
SELECT 种类, sum(已售出*售价)/(select sum(已售出*售价) from sale) as 各类销售占比 FROM sale group by 种类