请教查询语句写法

2个点 分别如下
[user]
uid,name
U12345,yuzd
U23456,lqp
U34567,yzh

[device]
id,name
1,22
2,23
3,22
4,DD

1个边
[uses]
uid,deviceId,time
U12345,1,1646409600
U23456,2,1646496000
U34567,3,1646582400
U34567,1,1646668800
U34567,2,1646755200

我想要通过
uid:U34567 在 设备1,2,3 登录过,
U12345也在设备1登录过
U23456也在设备2登录过

我想通过uid:U34567 找到 U12345 和 U23456,因为他们都登录过同设备

该怎么写查询语句

GO FROM “U34567” OVER user_login 后面我不知道该怎么下手了

这有一个类似的,通过服役在同一个球队连接起来一个球员和其他球员

  • 2 STEPS 是两跳
  • BIDIRECT 是双向,因为第二跳是反向的
  • DISTINCT 去重
  • dst(edge) 取最后的边的去向,其实是球队(对应你的就是共同设备,也就是第一跳)
  • src(edge) 取最后边的起点,就是你要的被连接的用户了
(root@nebula) [basketballplayer]> GO 2 STEPS FROM "player102" OVER serve BIDIRECT YIELD DISTINCT dst(edge);
+-----------+
| dst(EDGE) |
+-----------+
| "team203" |
| "team204" |
+-----------+
Got 2 rows (time spent 2829/62544 us)

Mon, 14 Mar 2022 11:06:57 CST

(root@nebula) [basketballplayer]> GO 2 STEPS FROM "player102" OVER serve BIDIRECT YIELD DISTINCT src(edge);
+-------------+
| src(EDGE)   |
+-------------+
| "player102" |
| "player135" |
| "player100" |
| "player101" |
| "player104" |
| "player103" |
| "player105" |
| "player106" |
| "player107" |
| "player108" |
| "player109" |
| "player110" |
| "player111" |
| "player112" |
| "player113" |
| "player114" |
| "player125" |
| "player138" |
+-------------+

所以你的这个可以:

GO 2 STEPS FROM "U34567" OVER user_login BIDIRECT YIELD DISTINCT src(edge);
2 个赞

ref: GO - Nebula Graph Database 手册

如果你觉得上面 wey 的回复解决了你的问题,可以勾选它为解决方案哈~