我在neo4j中創建了以下圖形。這裏USER1已經與用戶2和用戶3交換的消息如何使用ORDER BY並在密碼查詢中彙總結果
(user1)-[:EMAIL_SENT]->(Email)-[:EMAIL_TO]->(user2)
(user1)<-[:EMAIL_TO]-(Email)<-[:EMAIL_SENT]-(user2)
(user1)-[:EMAIL_SENT]->(Email)-[:EMAIL_TO]->(user3)
(user1)<-[:REPLY_TO]-(Email)<-[:REPLY_SENT]-(user3)
(user1)-[:REPLY_SENT]->(Email)-[:REPLY_TO]->(user3)
我想檢索USER1即Facebook的風格表明每個參與者的最新消息(發送或接收)。下面的查詢顯示了user1發送和接收的所有消息以及哪個參與者,但是我想彙總每個參與者的結果。
MATCH (U:User {username:'user1'})
-[L:EMAIL_SENT|EMAIL_TO]-(E:email)-[R:EMAIL_SENT|EMAIL_TO]-
(P:User)
WHERE type(L)<>type(R)
RETURN E.text as text,
E.subject as subject,
id(E) as message_id,
U.username as user,
P.username as participator,
(CASE type(L) WHEN 'EMAIL_SENT' THEN 'out' ELSE 'in' END) as direction
如果我嘗試這樣的事情
MATCH (U:User {username:'user1'})
-[L:EMAIL_SENT|EMAIL_TO]-(E:email)-[R:EMAIL_SENT|EMAIL_TO]-
(P:User)
WHERE type(L)<>type(R)
RETURN E.text as text,
E.subject as subject,
id(E) as message_id,
U.username as user,
P.username as participator,
(CASE type(L) WHEN 'EMAIL_SENT' THEN 'out' ELSE 'in' END) as direction ORDER BY E.timestamp DESC,collect (E.text)
我得到的錯誤 - 「爲了不能使用聚合,如果在前面的RETURN沒有聚集表達式(第5行,第1列(偏移:187))「返回E.text文本,」
而且,我不知道如何使用收集檢索所有郵件到特定的參與者
之前時間戳排序後組由參與者所有的電子郵件
是不是可以返回電子郵件的屬性,如文本(email.text)?像U.username一樣用戶 – jas
當然這是可能的。看一下更新。 –
它現在顯示方向爲空。在之前的查詢中,它顯示的方向爲REPLY_TO或REPLY_SENT或EMAIL_SENT或EMAIL_TO – jas