0

我正在试验 neo4j 中的日期。现在我想按 ISODateString 对结果进行排序。我创建了一个这样的密码查询:

MATCH(e:Expedition {id : "BJGYmzwZb"})-[pje]-(u:User) 
WHERE (e)-[:POSSIBLY_JOINS_EXPEDITION]-(u) OR (e)-[:JOINS_EXPEDITION]-(u) 
WITH e, u, apoc.date.parse(pje.createdAt, 's',"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") as date
ORDER by date 
OPTIONAL MATCH(u)<-[invitee:POSSIBLY_JOINS_EXPEDITION]-(e) 
OPTIONAL MATCH(u)-[attendee:JOINS_EXPEDITION]->(e)
OPTIONAL MATCH(u)-[applicant:POSSIBLY_JOINS_EXPEDITION]->(e) 
RETURN date, {user: properties(u), isInvitee: COUNT(invitee) > 0, isApplicant: COUNT(applicant) > 0, isAttendee: COUNT(attendee) > 0} as u

返回的结果没有正确排序。而以下查询确实以正确的顺序返回结果。我刚刚删除了带有OPTIONAL MATCH.

MATCH(e:Expedition {id : "BJGYmzwZb"})-[pje]-(u:User) 
WHERE (e)-[:POSSIBLY_JOINS_EXPEDITION]-(u) OR (e)-[:JOINS_EXPEDITION]-(u) 
WITH e, u, apoc.date.parse(pje.createdAt, 's',"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") as date 
ORDER by date
RETURN date, {user: properties(u)} as u

有什么建议我做错了吗?我需要以不同的方式处理OPTIONAL MATCH-additions 吗?

4

1 回答 1

1

放在语句ORDER by date之后,如下所示:RETURN

MATCH(e:Expedition {id : "BJGYmzwZb"})-[pje]-(u:User) 
WHERE (e)-[:POSSIBLY_JOINS_EXPEDITION]-(u) OR (e)-[:JOINS_EXPEDITION]-(u) 
WITH e, u, apoc.date.parse(pje.createdAt, 's',"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") as date
OPTIONAL MATCH(u)<-[invitee:POSSIBLY_JOINS_EXPEDITION]-(e) 
OPTIONAL MATCH(u)-[attendee:JOINS_EXPEDITION]->(e)
OPTIONAL MATCH(u)-[applicant:POSSIBLY_JOINS_EXPEDITION]->(e) 
RETURN date, {user: properties(u), isInvitee: COUNT(invitee) > 0, isApplicant: COUNT(applicant) > 0, isAttendee: COUNT(attendee) > 0} as u
ORDER by date 
于 2017-05-30T13:19:18.923 回答