Star

关于group by后结果疑问

执行以下两条语句

  1. go from -6687639107950853490 over Relation where Relation.relation_name == "user_user" && Relation._dst == 253814685655007938 yield Relation._dst as id, Relation._src as src, $$.Contact.userid as userid | go from $-.id over Relation where Relation.relation_name == "user_user" yield Relation._dst as id, $-.src as src, $-.id as contact_id, $-.userid as userid | go from $-.id over Relation where Relation.relation_name == "user_company" && (Relation.userid == "" || Relation.userid== $-.userid) yield distinct Relation._dst, $-.contact_id as u_id | group by $-.u_id yield $-.u_id, count(*);

  2. go from -6687639107950853490 over Relation where Relation.relation_name == "user_user" && (Relation._dst == 798233943211018399 || Relation._dst == 253814685655007938) yield Relation._dst as id, Relation._src as src, $$.Contact.userid as userid | go from $-.id over Relation where Relation.relation_name == "user_user" yield Relation._dst as id, $-.src as src, $-.id as contact_id, $-.userid as userid | go from $-.id over Relation where Relation.relation_name == "user_company" && (Relation.userid == "" || Relation.userid== $-.userid) yield distinct Relation._dst, $-.contact_id as u_id | group by $-.u_id yield $-.u_id, count(*);

第一条语句返回的结果为

第二条语句返回的结果为

两条语句中除了第一个go语句中的条件不一样,其余都一样。期望两条语句中id 为 253814685655007938 的count值一样,但是现在结果不同,有点奇怪?

sql能简化下吗?

看这张图能了解sql表达的意思了。


我想获取U0关联的每个U1通过U2关联c的数量。

上面两个sql 分别限定了只查一个U1 (id 为253814685655007938)和查两个U1(id 分别为253814685655007938,798233943211018399 )的结果,按照理论来说id为253814685655007938的count数应该相同。

返回结果是 每个U1对应的c的count数

应该是因为第一步的结果集更大,从第一步的结果集作为起点会查询到更多的边。可以先distinct然后在groupby。这个行为我们在master分支上已经进行了修改,go会默认distinct起点。

我在每一条go语句中都加入了distinct,结果和没加distinct 一样

上面提供的两条语句在最后是先distinct 后groupby的

distinct是针对yield的一行来说的,你要只distinct需要的属性。

目前我是在所有的yield行对所需的属性进行distinct 。
go from -6687639107950853490 over Relation where Relation.relation_name == "user_user" && (Relation._dst == 798233943211018399 || Relation._dst == 253814685655007938) yield distinct Relation._dst as id, $$.Contact.userid as userid | go from $-.id over Relation where Relation.relation_name == "user_user" yield distinct Relation._dst as id, $-.id as contact_id, $-.userid as userid | go from $-.id over Relation where Relation.relation_name == "user_company" && (Relation.userid == "" || Relation.userid== $-.userid) yield distinct $-.contact_id as u_id, Relation._dst | group by $-.u_id yield $-.u_id, count(*);

请问一下, 这样写还有问题吗?

count换成count_distinct


改完后的结果

方便贴一下第一步go的结果么

第一步go的结果

在看一下第二步go的结果,有可能是多的起点查出来多的结果扩展出来同样的邻点。

顺带问一下,目前是否支持直接在客户端中将查询结果保存成文件?

2.0支持

看结果是有同样的邻点。但是因为它们和不同的起点关联,所以count的时候应该还是会包含在内

浙ICP备20010487号