Example for Subquery; additional property for Movie DB

I have a couple of suggestions to improve the documentation.

  1. Add some interesting numeric fields to the Movie DB, such as Cost and BoxOffice.

  2. I figured out an interesting example using SubQuery. Cost of a movie is many digits and varies a lot, so it's a bit hard to look at without formatting. But if you format the Cost as a string, then it won't sort numerically. With Subqueries, you can do a sort of the Cost as Numeric and in the subsequent query, drop the Numeric column (which is ugly but accurate.)

CALL{
   MATCH (m:Movie)
   WITH m.title AS Title,
         m.cost AS CostNumber, // cost as numeric so we can sort
         apoc.number.format(m.cost, '$#,###') AS Cost // as a formatted string
         RETURN title, Cost, CostNumber  ORDER BY CostNumber  DESC  // ordered by Numeric
}
RETURN Title, Cost limit 100  // CostNumber is dropped
1 Like

You don't need a subquery for that

ORDER BY can sort by any fields that are visible to the clause

 MATCH (m:Movie)
 RETURN m.title AS Title,
     apoc.number.format(m.cost, '$#,###') AS Cost // as a formatted string
 ORDER BY m.cost  DESC
1 Like