--将字符串处理河滨处理为数组unnest(array_agg(a.qx)...
--数组转换为整数数组
--数组排序
--根据索引取最大最小值
select a.gld,a.sbbh,a.qx,b.合并 from st1 as a
left join (
select a.*,a.最小||'-'||a.最大 as 合并
from (
select a.*,sort(a.hebin),(sort(a.hebin)::int[])[1] as 最小,(sort(a.hebin)::int[])[array_length(a.hebin,1)] as 最大,array_length(a.hebin,1) as 数组数量 from (
select a.合并的值,string_to_array(replace(replace(array_to_string(array (select unnest(array_agg(a.qx))), ','),'-',','),',',','),',')::INTEGER[] as hebin
from (select 合并的值,qx from st1 order by qx) as a
group by a.合并的值
) as a) as a ) as b
on a.合并的值=b.合并的值
order by a.id
CREATE EXTENSION intarray;
select sort(ARRAY[6,5,2])
select array_sort(ARRAY[6,5,2])
string_to_array
PGSQL前后行合并为数组排序取最大最小值
最新推荐文章于 2023-12-18 15:40:02 发布
本文介绍了如何从字符串中提取并转换为整数数组,进行排序,以及根据索引获取最大值和最小值。通过SQL查询步骤,详细展示了数组agg和sort函数在处理河滨数据集时的应用。
396

被折叠的 条评论
为什么被折叠?



