-
Book Overview & Buying
-
Table Of Contents
Learning Cypher
By :
In our application, we have users who rate books with a score from one to five. Now, we are going to query the database to get some aggregated information about book scores.
Suppose that we want to know the number of users who have voted for a book. For this, we need to count the number of the vote relations between the users and that book, as shown in the following code snippet:
START b=node({id})
MATCH (b) <-[r:Vote]- (u:User)
RETURN COUNT(*) as votesThe only difference with the query patterns we already know is that here, we have used the COUNT function in the RETURN clause. With Cypher, the RETURN clause drives the aggregation of entities. In this case, as we have nothing else in the RETURN clause but the COUNT function, all the matching results are counted and the result is a single value. The result is as shown in the following output code:
+-------+ | votes | +-------+ | 7 | +-------+ 1 row
The arguments inside the COUNT...
Change the font size
Change margin width
Change background colour