对于以下查询,我只需要选择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) 我需要替换键:值对周围的方括号,类似于以下内容.任何帮助深表感谢!
'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) 对于子父关系表(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) distinct ×1
distinct-on ×1
for-loop ×1
hierarchy ×1
hive ×1
iteration ×1
postgresql ×1
python ×1
sql ×1