如何计算 collect() 列表中的元素并将该 count() 用于 WHERE 条件
how to count elements inside a collect() list and use that count() for a WHERE condition
希望得到一些帮助。
有以下查询:
MATCH (a:Academy)-[]-(w:Work)
RETURN collect(distinct a.name)as Associated_academies_for_this_book,w.shortTitle as
book_short_title, w.workId as Book_ID order by size(collect(distinct a.name)) desc
使用此输出:
result query
我只需要 return 结果在第一列的列表中有一个以上的元素(由 collect(distinct a.name) 生成的列),我尝试使用 count(collect)>1和类似的东西,但没有得到我需要的东西。
有什么想法吗?
非常感谢
您可以使用size
MATCH (a:Academy)-[]-(w:Work)
WITH collect(distinct a.name) as Associated_academies_for_this_book, w.shortTitle as book_short_title, w.WorkID as Book_ID
WHERE size(Associated_academies_for_this_book)>1
RETURN book_short_title, Book_ID
或
您可以使用 count
as referenced in 文档,聚合与 *
一起使用,应该会出现。
MATCH (a:Academy)-[]-(w:Work)
WITH collect(distinct a.name) as Associated_academies_for_this_book,
w.shortTitle as book_short_title, w.workId as Book_ID, count (*) as occ
WHERE occ>1
RETURN occ, Associated_academies_for_this_book, book_short_title, Book_ID
第二个将此信息作为 occ
变量与其他相关列存储在 WITH
语句中作为中间步骤,如果需要,您可以稍后使用它 on/in RETURN
语句。您可以使用 size
或 count
聚合。
希望得到一些帮助。
有以下查询:
MATCH (a:Academy)-[]-(w:Work)
RETURN collect(distinct a.name)as Associated_academies_for_this_book,w.shortTitle as
book_short_title, w.workId as Book_ID order by size(collect(distinct a.name)) desc
使用此输出: result query
我只需要 return 结果在第一列的列表中有一个以上的元素(由 collect(distinct a.name) 生成的列),我尝试使用 count(collect)>1和类似的东西,但没有得到我需要的东西。 有什么想法吗?
非常感谢
您可以使用size
MATCH (a:Academy)-[]-(w:Work)
WITH collect(distinct a.name) as Associated_academies_for_this_book, w.shortTitle as book_short_title, w.WorkID as Book_ID
WHERE size(Associated_academies_for_this_book)>1
RETURN book_short_title, Book_ID
或
您可以使用 count
as referenced in 文档,聚合与 *
一起使用,应该会出现。
MATCH (a:Academy)-[]-(w:Work)
WITH collect(distinct a.name) as Associated_academies_for_this_book,
w.shortTitle as book_short_title, w.workId as Book_ID, count (*) as occ
WHERE occ>1
RETURN occ, Associated_academies_for_this_book, book_short_title, Book_ID
第二个将此信息作为 occ
变量与其他相关列存储在 WITH
语句中作为中间步骤,如果需要,您可以稍后使用它 on/in RETURN
语句。您可以使用 size
或 count
聚合。