ngql 统计关联的边数count统计有误

这样写count统计有误
MATCH (n:player {name : “Tim Duncan”})<-[]-(v:player)<-[]-(for:player)
RETURN v,count(for)

实际我想要的杳询是
第一条
MATCH p=(n:player {name : “Tim Duncan”})<-[]-(v:player)
RETURN v

第二条
match (v)<-[]-(for:player) return count(for)

现在怎么把第一条语句合成一条
查询返回的结果是: return v,count(for)

你加个distinct 不就行了 count(distinct for)

1 个赞

没用的是个数有问题

你是想既返回点 又返回count 那这个是做不到的,同时返回是按照v进行分组count 不返回v才是全部的count,你这个又要明细值又要聚合值 没有这种计算逻辑

neo4j是这样写的match(n:player)<-[v:over]-(nb) return nb,size((nb)-[:over]-())

意思是查询上上个指向自已的边的个数

所以我需要一个复合查询把我这条neo4j语句换成ngql语句

就是想问怎么写一个复合语句,把这条neo4j语句换成nebula的ngql语句
match(n:player)<-[v:over]-(nb) return nb,size((nb)<-[:over]-())

你写的这个意思不就是计算 nb的入度吗 感觉就是你最开始写的啊 只不过count换成边就可以了 再去重

哪个统计的个数有问题,查询的时候count只有1条,match (v:player{code:‘11’})<-[]-(for:player) return count(for) 有13条,所以MATCH (n:player {name : “Tim Duncan”})<-[]-(v:player)<-[]-(for:player)
RETURN v,count(for) 这样写有问题

MATCH (n:player {name : “Tim Duncan”})<-[]-(v:player)<-[:g]-(for:player)
RETURN v,count(g) 这样写也是统计的边有问题的

我就是要通过a点把2,3,2的点查询出来,然后把2,3,2下面的子点个数也要查询出来

你分别把不同的结果贴出来

按你说的造了数据试试 没啥问题啊

1 个赞

match p=(na:Industry{code:'21020103'})<-[r:IndustryRelationship]
					-(nb:Industry)<-[v:IndustryRelationship]-(for:Industry)
					 return p,count(v)
p	
count(v)	
<("in21020103" :Industry{code: "21020103", is_leaf: "0", level: "4", name: "筛选煤", parent: "210201", remark: ""})<-[:IndustryRelationship@0 {primary_code: "210201", primary_name: "煤炭开采II", primary_type: "M", realtion: "1", related_code: "21020103", related_name: "筛选煤", related_type: "P", remark: "", status: "1", type: 1}]-("in210201" :Industry{code: "210201", is_leaf: "0", level: "3", name: "煤炭开采II", parent: "210200", remark: ""})<-[:IndustryRelationship@0 {primary_code: "2206020502", primary_name: "阻燃运输带", primary_type: "F", realtion: "1", related_code: "210201", related_name: "煤炭开采II", related_type: "P", remark: "", status: "1", type: 1}]-("in2206020502" :Industry{code: "2206020502", is_leaf: "1", level: "5", name: "阻燃运输带", parent: "22060205", remark: ""})>	1





match p=
					(nb:Industry{code:'210201'})<-[v:IndustryRelationship]-(for:Industry)
					 return p

p	
<("in210201" :Industry{code: "210201", is_leaf: "0", level: "3", name: "煤炭开采II", parent: "210200", remark: ""})<-[:IndustryRelationship@0 {primary_code: "210201", primary_name: "煤炭开采II", primary_type: "P", realtion: "-1", related_code: "21020101", related_name: "原煤", related_type: "M", remark: "", status: "1", type: 1}]-("in21020101" :Industry{code: "21020101", is_leaf: "0", level: "4", name: "原煤", parent: "210201", remark: ""})>
<("in210201" :Industry{code: "210201", is_leaf: "0", level: "3", name: "煤炭开采II", parent: "210200", remark: ""})<-[:IndustryRelationship@0 {primary_code: "210201", primary_name: "煤炭开采II", primary_type: "P", realtion: "-1", related_code: "220307", related_name: "民爆用品", related_type: "R", remark: "", status: "1", type: 1}]-("in220307" :Industry{code: "220307", is_leaf: "0", level: "3", name: "民爆用品", parent: "220300", remark: ""})>
<("in210201" :Industry{code: "210201", is_leaf: "0", level: "3", name: "煤炭开采II", parent: "210200", remark: ""})<-[:IndustryRelationship@0 {primary_code: "210201", primary_name: "煤炭开采II", primary_type: "P", realtion: "-1", related_code: "22060205", related_name: "耐油橡胶制品", related_type: "F", remark: "", status: "1", type: 1}]-("in22060205" :Industry{code: "22060205", is_leaf: "0", level: "4", name: "耐油橡胶制品", parent: "220602", remark: ""})>
<("in210201" :Industry{code: "210201", is_leaf: "0", level: "3", name: "煤炭开采II", parent: "210200", remark: ""})<-[:IndustryRelationship@0 {primary_code: "2206020502", primary_name: "阻燃运输带", primary_type: "F", realtion: "1", related_code: "210201", related_name: "煤炭开采II", related_type: "P", remark: "", status: "1", type: 1}]-("in2206020502" :Industry{code: "2206020502", is_leaf: "1", level: "5", name: "阻燃运输带", parent: "22060205", remark: ""})>
<("in210201" :Industry{code: "210201", is_leaf: "0", level: "3", name: "煤炭开采II", parent: "210200", remark: ""})<-[:IndustryRelationship@0 {primary_code: "210201", primary_name: "煤炭开采II", primary_type: "P", realtion: "-1", related_code: "610103", related_name: "商品混凝土", related_type: "M", remark: "", status: "1", type: 1}]-("in610103" :Industry{code: "610103", is_leaf: "0", level: "3", name: "商品混凝土", parent: "610100", remark: ""})>
<("in210201" :Industry{code: "210201", is_leaf: "0", level: "3", name: "煤炭开采II", parent: "210200", remark: ""})<-[:IndustryRelationship@0 {primary_code: "210201", primary_name: "煤炭开采II", primary_type: "P", realtion: "-1", related_code: "61010301", related_name: "防水混凝土", related_type: "M", remark: "", status: "1", type: 1}]-("in61010301" :Industry{code: "61010301", is_leaf: "1", level: "4", name: "防水混凝土", parent: "610103", remark: ""})>

match p=(na:Industry{code:‘21020103’})<-[r:IndustryRelationship]
-(nb:Industry)<-[v:IndustryRelationship]-(for:Industry)
return p,count(v)
p
count(v)
<(“in21020103” :Industry{code: “21020103”, is_leaf: “0”, level: “4”, name: “筛选煤”, parent: “210201”, remark: “”})<-[:IndustryRelationship@0 {primary_code: “210201”, primary_name: “煤炭开采II”, primary_type: “M”, realtion: “1”, related_code: “21020103”, related_name: “筛选煤”, related_type: “P”, remark: “”, status: “1”, type: 1}]-(“in210201” :Industry{code: “210201”, is_leaf: “0”, level: “3”, name: “煤炭开采II”, parent: “210200”, remark: “”})<-[:IndustryRelationship@0 {primary_code: “2206020502”, primary_name: “阻燃运输带”, primary_type: “F”, realtion: “1”, related_code: “210201”, related_name: “煤炭开采II”, related_type: “P”, remark: “”, status: “1”, type: 1}]-(“in2206020502” :Industry{code: “2206020502”, is_leaf: “1”, level: “5”, name: “阻燃运输带”, parent: “22060205”, remark: “”})> 1

match p=
(nb:Industry{code:‘210201’})<-[v:IndustryRelationship]-(for:Industry)
return p

p
<(“in210201” :Industry{code: “210201”, is_leaf: “0”, level: “3”, name: “煤炭开采II”, parent: “210200”, remark: “”})<-[:IndustryRelationship@0 {primary_code: “210201”, primary_name: “煤炭开采II”, primary_type: “P”, realtion: “-1”, related_code: “21020101”, related_name: “原煤”, related_type: “M”, remark: “”, status: “1”, type: 1}]-(“in21020101” :Industry{code: “21020101”, is_leaf: “0”, level: “4”, name: “原煤”, parent: “210201”, remark: “”})>
<(“in210201” :Industry{code: “210201”, is_leaf: “0”, level: “3”, name: “煤炭开采II”, parent: “210200”, remark: “”})<-[:IndustryRelationship@0 {primary_code: “210201”, primary_name: “煤炭开采II”, primary_type: “P”, realtion: “-1”, related_code: “220307”, related_name: “民爆用品”, related_type: “R”, remark: “”, status: “1”, type: 1}]-(“in220307” :Industry{code: “220307”, is_leaf: “0”, level: “3”, name: “民爆用品”, parent: “220300”, remark: “”})>
<(“in210201” :Industry{code: “210201”, is_leaf: “0”, level: “3”, name: “煤炭开采II”, parent: “210200”, remark: “”})<-[:IndustryRelationship@0 {primary_code: “210201”, primary_name: “煤炭开采II”, primary_type: “P”, realtion: “-1”, related_code: “22060205”, related_name: “耐油橡胶制品”, related_type: “F”, remark: “”, status: “1”, type: 1}]-(“in22060205” :Industry{code: “22060205”, is_leaf: “0”, level: “4”, name: “耐油橡胶制品”, parent: “220602”, remark: “”})>
<(“in210201” :Industry{code: “210201”, is_leaf: “0”, level: “3”, name: “煤炭开采II”, parent: “210200”, remark: “”})<-[:IndustryRelationship@0 {primary_code: “2206020502”, primary_name: “阻燃运输带”, primary_type: “F”, realtion: “1”, related_code: “210201”, related_name: “煤炭开采II”, related_type: “P”, remark: “”, status: “1”, type: 1}]-(“in2206020502” :Industry{code: “2206020502”, is_leaf: “1”, level: “5”, name: “阻燃运输带”, parent: “22060205”, remark: “”})>
<(“in210201” :Industry{code: “210201”, is_leaf: “0”, level: “3”, name: “煤炭开采II”, parent: “210200”, remark: “”})<-[:IndustryRelationship@0 {primary_code: “210201”, primary_name: “煤炭开采II”, primary_type: “P”, realtion: “-1”, related_code: “610103”, related_name: “商品混凝土”, related_type: “M”, remark: “”, status: “1”, type: 1}]-(“in610103” :Industry{code: “610103”, is_leaf: “0”, level: “3”, name: “商品混凝土”, parent: “610100”, remark: “”})>
<(“in210201” :Industry{code: “210201”, is_leaf: “0”, level: “3”, name: “煤炭开采II”, parent: “210200”, remark: “”})<-[:IndustryRelationship@0 {primary_code: “210201”, primary_name: “煤炭开采II”, primary_type: “P”, realtion: “-1”, related_code: “61010301”, related_name: “防水混凝土”, related_type: “M”, remark: “”, status: “1”, type: 1}]-(“in61010301” :Industry{code: “61010301”, is_leaf: “1”, level: “4”, name: “防水混凝土”, parent: “610103”, remark: “”})>

我的是这种情况

如果第2层只有2个点,你这样查询就会出问题

你返回的是p 这是整条路径,只有一条说明满足2度的只有一条路径,
你两条语句写的code好像还不一样啊 一个21020103 一个210201

浙ICP备20010487号