1

I'm trying to make a cypher query which does the following

  1. Find the top 10 largest USA organisations (in terms of revenue)
  2. Return "True" if an organisation part of the top 10, if not return "False"

My attempted code looks like this to extract list of top 10 organisations is:

MATCH (org)
WHERE org.revenueCurrency = 'USD'
WITH org as topCompany
ORDER by topCompany.revenue desc LIMIT 10
RETURN topCompany

however not sure how to return to True or False if a company is in the top 10

star_it8293
  • 399
  • 3
  • 12

1 Answers1

1

This is one way:

MATCH (org)
WHERE org.revenueCurrency = 'USD'
WITH org
ORDER by org.revenue DESC
WITH COLLECT(org) AS orgs
UNWIND [i IN RANGE(0, SIZE(orgs)-1) | {org: orgs[i], top10: i < 10}] AS result
RETURN result

The top10 property of each result row will be a boolean.

[UPDATE]

If you want each result row to be "flat" instead of a map, use this altered RETURN clause:

RETURN result.org AS org, result.top10 AS top10
cybersam
  • 63,203
  • 6
  • 53
  • 76
  • thanks, however this creates a property attribute. I need the actual result to return TRUE or FALSE for any given organisation node in the database – star_it8293 Jun 11 '20 at 23:00