SQL,计算同行中各列的中位数

postgresql的表T有多个数字列:


X Y Z
1 6 3 3
2 5 6 NULL
3 4 5 6
4 11 7 8

请计算出同行中各列的中位数:


MEDIAN
1 3
2 5
3 5
4 8

编写SPL代码:


A
1 =pg1.query("select * from T")
2 =A1.new(~.array().median())

函数new新建二维表,~表示当前记录,array将记录的字段值转为序列。

来源:https://stackoverflow.com/questions/78449368/how-to-get-the-row-wise-median-over-several-columns-of-a-postgresql-table