基本上,我有一个数组,我需要将一个数字乘以每个元素,例如:
x float[1,2,3,4,5];
x := x * 10; --of course I get the error here
所以输出将是: {10,20,30,40,50}
最佳答案
您可以使用 unnest
-> 进行计算 -> array_agg
:
SELECT array_agg(unnest * 10) FROM UNNEST('{1,2,3,4,5}' :: int[])
要确定元素的顺序,您可以添加 WITH ORDINALITY
:
SELECT array_agg(unnest * 10 ORDER BY ordinality)
FROM UNNEST('{1,2,3,4,5}' :: int[] )WITH ORDINALITY
关于sql - 在 SQL 中,如何将一个数字乘以一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49328654/