sql - 如何将列乘以从先前查询中获得的值?
问题描述
我计算了表中两列的斜率和截距:
select regr_slope(x, y) slope, regr_intercept(x, y) intercept
from table
现在我想将列 x 与斜率相乘并添加截距,如下所示:
select x, y, slope * x + intercept as y_fit
from table
如何在一个查询中实现这一目标?
解决方案
您可以使用窗口函数:
select x, y,
regr_slope(x, y) over () * x + regr_intercept(x, y) over () as y_fit
from table
推荐阅读
- mysql - mysql group_concat 条件在哪里
- ios - 如何在 iOS swift 中一次对相同的对象使用动画师行为和手势?
- python - 添加时间不起作用但减去工作 - Python
- java - Java selenium 巨大的循环列表
- javascript - 如何计算 Javascript 中的总小时数?
- java - 错误说包不存在,但它不是一个包,只是一个arrayList......这是怎么回事?
- tinymce - TinyMCE - 让 div 像 img 一样调整大小
- python - 并排显示多个 matplotlib 图形对象
- vagrant - 升级到 Ubuntu 18.04 后,以下 SSH 命令以非零退出状态响应
- jmeter - Jmeter 为 Blaze 仪表记录抛出 500 个无效字符错误