Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张看起来像这样的桌子
n1 | n2 | n3 | n4 --------------------- 40 60 40 30 50 50 55.5 20 80 40 40.5 30
我想将每一列乘以
n1*0.7 n2*0.1 n3*0.05 n4*0.05
从中得到总和
sum=(n1+n2+n3+n4)
并根据总行数计算平均值
有没有办法在 mysql 查询上实现这一点?
只需使用AVG平均功能:
AVG
SELECT AVG(0.7*n1 + 0.1*n2 + 0.05*n3 + 0.05*n4) AS avg_value FROM yourTable;