概述
WHERE子句将别名中满足条件的数据行保留,不满足条件的数据行舍弃。
语法
WHERE <condition>
// 开发中
WHERE <query>
<condition>
为判断条件表达式,保留判断为真的数据行<query>
为查询语句,保留有查询结果的数据行
WHERE子句后必须有其他子句对流入WHERE子句的别名,或该别名的同源别名进行操作,否则该语句无效。
例如,将两个异源别名n1和n2进行比较,如果点颜色相同则保留:

find().nodes({shape == "square"}) as n1
find().nodes({shape == "round"}) as n2
where n1.color == n2.color
return n1, n2
示例
用条件表达式进行判断
示例图集:

在一个空图集中,依次运行以下各行语句创建示例图集:
create().node_schema("student").node_schema("course")
create().node_property(@*, "name").node_property(@student, "age", int32).node_property(@course, "credit", int32)
insert().into(@student).nodes([{_id:"S001", _uuid:1, name:"Jason", age:25}, {_id:"S002", _uuid:2, name:"Lina", age:23}, {_id:"S003", _uuid:3, name:"Eric", age:24}, {_id:"S004", _uuid:4, name:"Emma", age:26}, {_id:"S005", _uuid:5, name:"Pepe", age:24}])
insert().into(@course).nodes([{_id:"C001", _uuid:6, name:"French", credit:4}, {_id:"C002", _uuid:7, name:"Math", credit:5}])
insert().into(@default).edges([{_uuid:1, _from_uuid:1, _to_uuid:6}, {_uuid:2, _from_uuid:2, _to_uuid:6}, {_uuid:3, _from_uuid:3, _to_uuid:6}, {_uuid:4, _from_uuid:2, _to_uuid:7}, {_uuid:5, _from_uuid:3, _to_uuid:7}, {_uuid:6, _from_uuid:4, _to_uuid:7}, {_uuid:7, _from_uuid:5, _to_uuid:7}])
本例查询“课程-[]-学生”1步路径,路径中课程的credit属性为4或学生的age属性为24时,返回路径中点和边的全部信息:
n({@course} as a).e().n({@student} as b) as p
where a.credit == 4 || b.age == 24
return p{*}
French <---- Jason
French <---- Lina
French <---- Eric
Math <---- Pepe
Math <---- Eric
用查询语句进行判断(开发中)
本例查找满足下图所示条件的中介银行卡agent,即银行卡CA002经由agent向银行卡CA001转账,同时agent是CA003的2步内邻居:

n({_id == "CA002"}).re().n({@card} as agent).re().n({_id == "CA001"})
where n(agent).e()[*:2].n({_id == "CA003"})
return agent{*}
WHERE子句对路径查询子句输出的别名agent做进一步的过滤:对于每一个agent,判断其到CA003的2步内最短路径是否存在,如果存在,则将该agent传给后面的RETURN子句。
上例也可以用子图模板子句实现:
subgraph([
n({_id == "CA002"}).re().n({@card} as agent).re().n({_id == "CA001"}),
n(agent).e()[*:2].n({_id == "CA003"})
])
return agent{*}