[英]Want to calculate cumulative percentage from one table to another table multiple columns
输入
Table 1 Table 2
Amount 1 2 3 4 5
100 10 10 10 10 10
200 20 20 20 20 20
Output
1 2 3 4 5
10% 20% 30% 40% 50%
10% 20% 30% 40% 50%
我尝试在 EXCEL 中执行此操作并成功,但现在数据太大,无法在 excel 中执行此操作
不适用
\
我假设两个表中都有一些列可用于连接表(没有这个,您的问题将无法解决,除非每个表中只有一条记录)。
所以假设以下表结构:
table1
id
amount
table2
id
col1
col2
col3
col4
col5
您可以连接两个表并按如下方式进行计算:
select
t2.col1/t1.amount as col1,
(t2.col1 + t2.col2)/t1.amount as col2,
(t2.col1 + t2.col2 + t2.col3)/t1.amount as col3,
(t2.col1 + t2.col2 + t2.col3 + t2.col4)/t1.amount as col4,
(t2.col1 + t2.col2 + t2.col3 + t2.col4 + t2.col5)/t1.amount as col5
from table1 t1
inner join table2 t2 on t2.id = t1.id
结果集中的每一列(除了id
)将包含一个介于 0 和 1 之间的数值,它表示amount
的累积部分。 然后,您可以处理应用程序中的百分比格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.