小编Sar*_*ist的帖子

PostgreSQL:根据排序顺序仅选择每个id的第一条记录

对于以下查询,我只需要选择shape_type值最小的第一条记录(范围从1到10).如果你有任何关于如何轻松做到这一点的知识是postgresql,请帮忙.谢谢你的时间.

select g.geo_id, gs.shape_type
from schema.geo g   
join schema.geo_shape gs on (g.geo_id=gs.geo_id)  
order by gs.shape_type asc;
Run Code Online (Sandbox Code Playgroud)

sql postgresql distinct greatest-n-per-group distinct-on

14
推荐指数
1
解决办法
1万
查看次数

Hive:regexp_replace方括号

我需要替换键:值对周围的方括号,类似于以下内容.任何帮助深表感谢!

'properties'中的数据如下所示:

name: property1
value: [12345667:97764458]

**code**
SELECT p.name, regexp_replace(p.value,'[','') AS value
FROM properties p
Run Code Online (Sandbox Code Playgroud)

解决:修改后的代码

SELECT p.name, regexp_replace(p.value,'\\[|\\]','') AS value
FROM properties p;
Run Code Online (Sandbox Code Playgroud)

hive square-bracket

5
推荐指数
1
解决办法
1万
查看次数

Python:父子层次结构的组合

对于子父关系表(csv),我尝试使用表中的所有数据收集可能的父子关系组合链。我正在尝试解决一个问题,如果存在多个子父级(参见第 3 行和第 4 行),则第二个子父级组合(第 4 行)不包含在迭代中。

数据示例:

孩子,父母

A,B
A,C
B,D
B,C
C,D
Run Code Online (Sandbox Code Playgroud)

预期连锁结果:

D|B|A
D|C|B|A
D|C|A
Run Code Online (Sandbox Code Playgroud)

实际连锁结果:

D|B|A
D|C|A
Run Code Online (Sandbox Code Playgroud)

代码

find= 'A' #The child for which the code should find all possible parent relationships
sequence = ''
with open('testing.csv','r') as f:     #testing.csv = child,parent table (above example)
    for row in f:
        if row.strip().startswith(find):
            parent = row.strip().split(',')[1]
            sequence = parent + '|' + find
            f1 = open('testing.csv','r')
            for row in f1:
                if row.strip().startswith(parent):
                    parent2 = row.strip().split(',')[1]
                    sequence = parent2 …
Run Code Online (Sandbox Code Playgroud)

python iteration for-loop hierarchy

3
推荐指数
1
解决办法
7882
查看次数