嗨,这是我当前想要“重新过滤”的查询:
START movie = node(*)
MATCH user-[:LIKE]->category-[:SIMILAR*0..3]-()<-[:TAGGED]->movie
WHERE user.name = "current_user"
WITH DISTINCT movie, user, category
RETURN user.name, category.name, ID(movie), movie.name
ORDER BY movie.name;
http://console.neo4j.org/r/u19iim
这是当前查询后的样子:
+--------------+----------------+-----------+-------------------------+
| user.name | category.name | ID(movie) | movie.name |
+--------------+----------------+-----------+-------------------------+
| current_user | c | 14 | movie_c_and_d_and_e |
| current_user | d | 14 | movie_c_and_d_and_e |
| current_user | e | 14 | movie_c_and_d_and_e |
| current_user | a | 9 | movie_of_a_and_b_and_b1 |
| current_user | b | 9 | movie_of_a_and_b_and_b1 |
| current_user | b | 10 | movie_of_b2_first |
| current_user | b | 11 | movie_of_b2_second |
| current_user | c | 12 | movie_of_c |
| current_user | d | 13 | movie_of_d_and_e |
| current_user | e | 13 | movie_of_d_and_e |
+--------------+----------------+-----------+-------------------------+
我想GROUP BY COUNT(sugg) AS category_count
提取这个:
+--------------+----------------+-----------+-------------------------+
| user.name | category_count | ID(movie) | movie.name |
+--------------+----------------+-----------+-------------------------+
| current_user | 3 | 14 | movie_c_and_d_and_e |
| current_user | 2 | 9 | movie_of_a_and_b_and_b1 |
| current_user | 2 | 13 | movie_of_d_and_e |
| current_user | 1 | 10 | movie_of_b2_first |
| current_user | 1 | 11 | movie_of_b2_second |
| current_user | 1 | 12 | movie_of_c |
+--------------+----------------+-----------+-------------------------+
我怎样才能做到这一点?
类似的问题: -如何在 neo4j 的密码查询中有两个聚合?
更新
这是工作结果(带有演示:http ://tinyurl.com/cywlycc ):
START movie = node(*)
MATCH user-[:LIKE]->category-[:SIMILAR*0..3]-()<-[:TAGGED]->movie
WHERE user.name = "current_user"
WITH DISTINCT movie, category WITH COUNT(movie) AS category_count, movie, collect(category.name) as categorized
RETURN category_count, ID(movie), movie.name, categorized
ORDER BY category_count DESC;