1

こんにちは、「再フィルタリング」したい現在のクエリは次のとおりです。

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 の暗号クエリで 2 つの集計を行う方法は?

更新
作業結果は次のとおりです(デモ付き: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;
4

1 に答える 1

2
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, count(category.name) as category_count, ID(movie), movie.name 
ORDER BY category_count desc, movie.name asc

http://console.neo4j.org/r/69rfkn

于 2013-02-15T21:34:44.117 に答える