赞
踩
一个SQL让你认识array相关函数~~~come on~
- with tmp as
- (
- select t.node,t.parent,collect_set(parent) over() as parent_set --就是一个array类型数据
- from
- (
- select 4 as node,2 as parent
- union all select 5 as node,2 as parent
- union all select 6 as node,3 as parent
- union all select 7 as node,3 as parent
- union all select 2 as node,1 as parent
- union all select 3 as node,1 as parent
- union all select 1 as node,null as parent
- ) t
- )
- select node,parent,parent_set
- ,parent_set[0] --取array中第一个值
- ,sort_array(parent_set) --对array进行排序,只能升序,不能指定降序
- ,size(parent_set) --对array计数
- ,array_contains(parent_set,node) --检索array中是否有当前node
- from tmp
结果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。