的时候我就喜欢做这样的事情使用子查询,而不使用子查询有总:选择总不分割
select
category,
date,
sum(qty)/(select sum(qty) from table where t.date= table.date) as share_of_total
from table t
group by category,date;
表看起来是这样的:
category date qty
1 2016-11-01 3
1 2016-12-01 4
2 2016-12-01 6
2 2016-11-01 7
预期结果如下:
category date share_of_total
1 2016-11-01 30%
2 2016-11-01 70%
1 2016-12-01 40%
2 2016-12-01 60%
请给出表格定义和数据,以帮助您完成 –
!希望现在更清楚。 –