![](/img/trans.png)
[英]How do I create a new table in SQL using the row values of another table as column names (dynamic)?
[英]I want to add new row in my table but I want to do mathematical operation using column names (SQL)
我有一张这样的桌子
2001年 | 2002年 | 2003年 |
---|---|---|
125.000 | 313.000 | 515.00 |
我想将年增长率添加为行
您应该将表结构更改为:
year | val
2001 | 125.000
2002 | 313.000
2003 | 515.00
然后用LAG
解析function:
SELECT
year,
val,
100.0*(val - LAG(val) OVER (ORDER BY year)) / LAG(val) OVER (ORDER BY YEAR) AS pct_growth
FROM yourTable
ORDER BY year;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.