🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 2 (from laksa067)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
14 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.5 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.markhneedham.com/blog/2013/02/24/neo4jcypher-combining-count-and-collect-in-one-query/
Last Crawled2026-04-03 03:00:55 (14 days ago)
First Indexed2021-04-24 10:26:41 (4 years ago)
HTTP Status Code200
Meta Titleneo4j/cypher: Combining COUNT and COLLECT in one query | Mark Needham
Meta DescriptionIn my continued playing around with football data I wanted to write a cypher query against neo4j which would show me which teams had missed the most penalties this season and who missed them. I started off with a query that returned all the penalties that have been missed this season and the games those misses happened in: START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team, game-[:home_team]-home, game-[:away_team]-away RETURN player.
Meta Canonicalnull
Boilerpipe Text
24 Feb 2013 · neo4j cypher In my continued playing around with football data I wanted to write a cypher query against neo4j which would show me which teams had missed the most penalties this season and who missed them. I started off with a query that returned all the penalties that have been missed this season and the games those misses happened in: START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team, game-[:home_team]-home, game-[:away_team]-away RETURN player.name, team.name, home.name, away.name +-------------------------------------------------------------------------------------------------+ | player.name | team.name | home.name | away.name | +-------------------------------------------------------------------------------------------------+ | "Papiss Demba Cisse" | "Newcastle United" | "Newcastle United" | "Norwich City" | | "Wayne Rooney" | "Manchester United" | "Manchester United" | "Arsenal" | | "Mikel Arteta" | "Arsenal" | "Arsenal" | "Fulham" | | "David Silva" | "Manchester City" | "Manchester City" | "Southampton" | | "Frank Lampard" | "Chelsea" | "Manchester City" | "Chelsea" | | "Adel Taarabt" | "Queens Park Rangers" | "Queens Park Rangers" | "Norwich City" | | "Javier Hernández" | "Manchester United" | "Manchester United" | "Wigan Athletic" | | "Robin Van Persie" | "Manchester United" | "Southampton" | "Manchester United" | | "Jonathan Walters" | "Stoke City" | "Fulham" | "Stoke City" | | "Shane Long" | "West Bromwich Albion" | "West Bromwich Albion" | "Liverpool" | | "Steven Gerrard" | "Liverpool" | "Liverpool" | "West Bromwich Albion" | | "Lucas Piazon" | "Chelsea" | "Chelsea" | "Aston Villa" | +-------------------------------------------------------------------------------------------------+ 12 rows (there should actually be another penalty miss for Jonathan Walters against Chelsea but for some reason the data source has missed it off! I then grouped the penalty misses by team so that I’d have one row for each team and a collection showing the people who’d missed. We can use the http://docs.neo4j.org/chunked/milestone/query-aggregation.html#aggregation-collect function to do the latter: START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team RETURN DISTINCT team.name, COLLECT(player.name) AS players +---------------------------------------------------------------------------------+ | team.name | players | +---------------------------------------------------------------------------------+ | "Newcastle United" | ["Papiss Demba Cisse"] | | "Manchester United" | ["Wayne Rooney","Javier Hernández","Robin Van Persie"] | | "Stoke City" | ["Jonathan Walters"] | | "West Bromwich Albion" | ["Shane Long"] | | "Chelsea" | ["Frank Lampard","Lucas Piazon"] | | "Arsenal" | ["Mikel Arteta"] | | "Manchester City" | ["David Silva"] | | "Liverpool" | ["Steven Gerrard"] | | "Queens Park Rangers" | ["Adel Taarabt"] | +---------------------------------------------------------------------------------+ 9 rows I wanted to order the teams by the number of penalties they’d missed so Manchester United would be first in the table in this case and initially tried to order the results by a count of players: START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team RETURN DISTINCT team.name, COLLECT(player.name) AS players ORDER BY COUNT(player.name) which doesn’t actually compile: SyntaxException: Aggregation expressions must be listed in the RETURN clause to be used in ORDER BY I tried a few other variations such as the following: START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team RETURN DISTINCT team.name, COUNT(player.name) AS numberOfPlayers, COLLECT(player.name) AS players ORDER BY numberOfPlayers DESC which again doesn’t compile: SyntaxException: Aggregation expressions must be listed in the RETURN clause to be used in ORDER BY I eventually found a post by Andres where he explains that you need to split the query into two and make use of http://docs.neo4j.org/chunked/milestone/query-with.html if you want to make use of two aggregation expressions. I ended up with the following query which does the job: START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team WITH DISTINCT team, COLLECT(player.name) AS players MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team WITH DISTINCT team, COUNT(player) AS numberOfPlayers, players RETURN team.name, players ORDER BY numberOfPlayers DESC +---------------------------------------------------------------------------------+ | team.name | players | +---------------------------------------------------------------------------------+ | "Manchester United" | ["Wayne Rooney","Javier Hernández","Robin Van Persie"] | | "Chelsea" | ["Frank Lampard","Lucas Piazon"] | | "Liverpool" | ["Steven Gerrard"] | | "Manchester City" | ["David Silva"] | | "Newcastle United" | ["Papiss Demba Cisse"] | | "Queens Park Rangers" | ["Adel Taarabt"] | | "Stoke City" | ["Jonathan Walters"] | | "Arsenal" | ["Mikel Arteta"] | | "West Bromwich Albion" | ["Shane Long"] | +---------------------------------------------------------------------------------+ 9 rows
Markdown
[![Mark Needham](https://www.markhneedham.com/blog//me.jpg)](https://www.markhneedham.com/blog/) # [Mark Needham](https://www.markhneedham.com/blog/) 24 Feb 2013 · [neo4j](https://www.markhneedham.com/blog/tag/neo4j/) [cypher](https://www.markhneedham.com/blog/tag/cypher/) # neo4j/cypher: Combining COUNT and COLLECT in one query In my [continued](http://www.markhneedham.com/blog/2013/02/19/neo4jcypher-using-a-where-clause-to-filter-paths/) [playing around](http://www.markhneedham.com/blog/2013/02/17/neo4jcypher-sql-style-group-by-functionality/) with football data I wanted to write a cypher query against neo4j which would show me which teams had missed the most penalties this season and who missed them. I started off with a query that returned all the penalties that have been missed this season and the games those misses happened in: ``` START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team, game-[:home_team]-home, game-[:away_team]-away RETURN player.name, team.name, home.name, away.name ``` ``` +-------------------------------------------------------------------------------------------------+ | player.name | team.name | home.name | away.name | +-------------------------------------------------------------------------------------------------+ | "Papiss Demba Cisse" | "Newcastle United" | "Newcastle United" | "Norwich City" | | "Wayne Rooney" | "Manchester United" | "Manchester United" | "Arsenal" | | "Mikel Arteta" | "Arsenal" | "Arsenal" | "Fulham" | | "David Silva" | "Manchester City" | "Manchester City" | "Southampton" | | "Frank Lampard" | "Chelsea" | "Manchester City" | "Chelsea" | | "Adel Taarabt" | "Queens Park Rangers" | "Queens Park Rangers" | "Norwich City" | | "Javier Hernández" | "Manchester United" | "Manchester United" | "Wigan Athletic" | | "Robin Van Persie" | "Manchester United" | "Southampton" | "Manchester United" | | "Jonathan Walters" | "Stoke City" | "Fulham" | "Stoke City" | | "Shane Long" | "West Bromwich Albion" | "West Bromwich Albion" | "Liverpool" | | "Steven Gerrard" | "Liverpool" | "Liverpool" | "West Bromwich Albion" | | "Lucas Piazon" | "Chelsea" | "Chelsea" | "Aston Villa" | +-------------------------------------------------------------------------------------------------+ 12 rows ``` (there should actually be another penalty miss for Jonathan Walters against Chelsea but for some reason the data source has missed it off\! I then grouped the penalty misses by team so that I’d have one row for each team and a collection showing the people who’d missed. We can use the http://docs.neo4j.org/chunked/milestone/query-aggregation.html\#aggregation-collect function to do the latter: ``` START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team RETURN DISTINCT team.name, COLLECT(player.name) AS players ``` ``` +---------------------------------------------------------------------------------+ | team.name | players | +---------------------------------------------------------------------------------+ | "Newcastle United" | ["Papiss Demba Cisse"] | | "Manchester United" | ["Wayne Rooney","Javier Hernández","Robin Van Persie"] | | "Stoke City" | ["Jonathan Walters"] | | "West Bromwich Albion" | ["Shane Long"] | | "Chelsea" | ["Frank Lampard","Lucas Piazon"] | | "Arsenal" | ["Mikel Arteta"] | | "Manchester City" | ["David Silva"] | | "Liverpool" | ["Steven Gerrard"] | | "Queens Park Rangers" | ["Adel Taarabt"] | +---------------------------------------------------------------------------------+ 9 rows ``` I wanted to order the teams by the number of penalties they’d missed so Manchester United would be first in the table in this case and initially tried to order the results by a count of players: ``` START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team RETURN DISTINCT team.name, COLLECT(player.name) AS players ORDER BY COUNT(player.name) ``` which doesn’t actually compile: ``` SyntaxException: Aggregation expressions must be listed in the RETURN clause to be used in ORDER BY ``` I tried a few other variations such as the following: ``` START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team RETURN DISTINCT team.name, COUNT(player.name) AS numberOfPlayers, COLLECT(player.name) AS players ORDER BY numberOfPlayers DESC ``` which again doesn’t compile: ``` SyntaxException: Aggregation expressions must be listed in the RETURN clause to be used in ORDER BY ``` I eventually found [a post by Andres](http://stackoverflow.com/questions/12269009/returning-two-aggregates-in-a-single-cypher-query?rq=1) where he explains that you need to split the query into two and make use of http://docs.neo4j.org/chunked/milestone/query-with.html if you want to make use of two aggregation expressions. I ended up with the following query which does the job: ``` START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team WITH DISTINCT team, COLLECT(player.name) AS players MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team WITH DISTINCT team, COUNT(player) AS numberOfPlayers, players RETURN team.name, players ORDER BY numberOfPlayers DESC ``` ``` +---------------------------------------------------------------------------------+ | team.name | players | +---------------------------------------------------------------------------------+ | "Manchester United" | ["Wayne Rooney","Javier Hernández","Robin Van Persie"] | | "Chelsea" | ["Frank Lampard","Lucas Piazon"] | | "Liverpool" | ["Steven Gerrard"] | | "Manchester City" | ["David Silva"] | | "Newcastle United" | ["Papiss Demba Cisse"] | | "Queens Park Rangers" | ["Adel Taarabt"] | | "Stoke City" | ["Jonathan Walters"] | | "Arsenal" | ["Mikel Arteta"] | | "West Bromwich Albion" | ["Shane Long"] | +---------------------------------------------------------------------------------+ 9 rows ``` - [Email](mailto:?subject=neo4j%2fcypher%3a%20Combining%20COUNT%20and%20COLLECT%20in%20one%20query&body=https://www.markhneedham.com/blog/2013/02/24/neo4jcypher-combining-count-and-collect-in-one-query/) - [Facebook](https://www.facebook.com/sharer/sharer.php?u=https://www.markhneedham.com/blog/2013/02/24/neo4jcypher-combining-count-and-collect-in-one-query/) - [Twitter](http://twitter.com/home?status=neo4j%2Fcypher%3A%20Combining%20COUNT%20and%20COLLECT%20in%20one%20query%20https://www.markhneedham.com/blog/2013/02/24/neo4jcypher-combining-count-and-collect-in-one-query/) - [LinkedIn](http://www.linkedin.com/shareArticle?mini=true&url=https://www.markhneedham.com/blog/2013/02/24/neo4jcypher-combining-count-and-collect-in-one-query/&title=neo4j%2Fcypher%3A%20Combining%20COUNT%20and%20COLLECT%20in%20one%20query&summary=In%20my%20continued%20playing%20around%20with%20football%20data%20I%20wanted%20to%20write%20a%20cypher%20query%20against%20neo4j%20which%20would%20show%20me%20which%20teams%20had%20missed%20the%20most%20penalties%20this%20season%20and%20who%20missed%20them.%0AI%20started%20off%20with%20a%20query%20that%20returned%20all%20the%20penalties%20that%20have%20been%20missed%20this%20season%20and%20the%20games%20those%20misses%20happened%20in%3A%0ASTART%20player%20%3D%20node%3Aplayers%28%26%2339%3Bname%3A%2A%26%2339%3B%29%20MATCH%20player-%5B%3Amissed_penalty_in%5D-game%2C%20player-%5B%3Aplayed%7Csubbed_on%5D-stats-%5B%3Ain%5D-game%2C%20stats-%5B%3Afor%5D-team%2C%20game-%5B%3Ahome_team%5D-home%2C%20game-%5B%3Aaway_team%5D-away%20RETURN%20player....) - [Tumblr](http://www.tumblr.com/share?v=3&u=https%3A%2F%2Fwww.markhneedham.com%2Fblog%2F2013%2F02%2F24%2Fneo4jcypher-combining-count-and-collect-in-one-query%2F&t=neo4j/cypher:%20Combining%20COUNT%20and%20COLLECT%20in%20one%20query) - [Reddit](http://www.reddit.com/submit?url=https://www.markhneedham.com/blog/2013/02/24/neo4jcypher-combining-count-and-collect-in-one-query/) - [Google+](https://plus.google.com/share?url=https://www.markhneedham.com/blog/2013/02/24/neo4jcypher-combining-count-and-collect-in-one-query/) - [Pinterest](http://pinterest.com/pin/create/button/?url=https://www.markhneedham.com/blog/2013/02/24/neo4jcypher-combining-count-and-collect-in-one-query/&media=https://www.markhneedham.com/blog/logo.png&description=neo4j/cypher:%20Combining%20COUNT%20and%20COLLECT%20in%20one%20query) - [Pocket](https://getpocket.com/save?url=https://www.markhneedham.com/blog/2013/02/24/neo4jcypher-combining-count-and-collect-in-one-query/) ##### About the author [I'm](https://twitter.com/markhneedham) currently working on short form content at [ClickHouse](https://clickhouse.com/). I publish short 5 minute videos showing how to solve data problems on YouTube [@LearnDataWithMark](https://www.youtube.com/@LearnDataWithMark). I previously worked on graph analytics at [Neo4j](https://neo4j.com/), where I also co-authored the [O'Reilly Graph Algorithms Book](https://www.oreilly.com/library/view/graph-algorithms/9781492047674/) with Amy Hodler. Please enable JavaScript to view the [comments powered by Disqus.](https://disqus.com/?ref_noscript) © Mark Needham. All rights reserved. Powered by [Hugo](http://gohugo.io/). [Crisp](https://github.com/kathyqian/crisp-ghost-theme) theme by [Kathy Qian](http://kathyqian.com/).
Readable Markdown
24 Feb 2013 · [neo4j](https://www.markhneedham.com/blog/tag/neo4j/) [cypher](https://www.markhneedham.com/blog/tag/cypher/) In my [continued](http://www.markhneedham.com/blog/2013/02/19/neo4jcypher-using-a-where-clause-to-filter-paths/) [playing around](http://www.markhneedham.com/blog/2013/02/17/neo4jcypher-sql-style-group-by-functionality/) with football data I wanted to write a cypher query against neo4j which would show me which teams had missed the most penalties this season and who missed them. I started off with a query that returned all the penalties that have been missed this season and the games those misses happened in: ``` START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team, game-[:home_team]-home, game-[:away_team]-away RETURN player.name, team.name, home.name, away.name ``` ``` +-------------------------------------------------------------------------------------------------+ | player.name | team.name | home.name | away.name | +-------------------------------------------------------------------------------------------------+ | "Papiss Demba Cisse" | "Newcastle United" | "Newcastle United" | "Norwich City" | | "Wayne Rooney" | "Manchester United" | "Manchester United" | "Arsenal" | | "Mikel Arteta" | "Arsenal" | "Arsenal" | "Fulham" | | "David Silva" | "Manchester City" | "Manchester City" | "Southampton" | | "Frank Lampard" | "Chelsea" | "Manchester City" | "Chelsea" | | "Adel Taarabt" | "Queens Park Rangers" | "Queens Park Rangers" | "Norwich City" | | "Javier Hernández" | "Manchester United" | "Manchester United" | "Wigan Athletic" | | "Robin Van Persie" | "Manchester United" | "Southampton" | "Manchester United" | | "Jonathan Walters" | "Stoke City" | "Fulham" | "Stoke City" | | "Shane Long" | "West Bromwich Albion" | "West Bromwich Albion" | "Liverpool" | | "Steven Gerrard" | "Liverpool" | "Liverpool" | "West Bromwich Albion" | | "Lucas Piazon" | "Chelsea" | "Chelsea" | "Aston Villa" | +-------------------------------------------------------------------------------------------------+ 12 rows ``` (there should actually be another penalty miss for Jonathan Walters against Chelsea but for some reason the data source has missed it off\! I then grouped the penalty misses by team so that I’d have one row for each team and a collection showing the people who’d missed. We can use the http://docs.neo4j.org/chunked/milestone/query-aggregation.html\#aggregation-collect function to do the latter: ``` START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team RETURN DISTINCT team.name, COLLECT(player.name) AS players ``` ``` +---------------------------------------------------------------------------------+ | team.name | players | +---------------------------------------------------------------------------------+ | "Newcastle United" | ["Papiss Demba Cisse"] | | "Manchester United" | ["Wayne Rooney","Javier Hernández","Robin Van Persie"] | | "Stoke City" | ["Jonathan Walters"] | | "West Bromwich Albion" | ["Shane Long"] | | "Chelsea" | ["Frank Lampard","Lucas Piazon"] | | "Arsenal" | ["Mikel Arteta"] | | "Manchester City" | ["David Silva"] | | "Liverpool" | ["Steven Gerrard"] | | "Queens Park Rangers" | ["Adel Taarabt"] | +---------------------------------------------------------------------------------+ 9 rows ``` I wanted to order the teams by the number of penalties they’d missed so Manchester United would be first in the table in this case and initially tried to order the results by a count of players: ``` START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team RETURN DISTINCT team.name, COLLECT(player.name) AS players ORDER BY COUNT(player.name) ``` which doesn’t actually compile: ``` SyntaxException: Aggregation expressions must be listed in the RETURN clause to be used in ORDER BY ``` I tried a few other variations such as the following: ``` START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team RETURN DISTINCT team.name, COUNT(player.name) AS numberOfPlayers, COLLECT(player.name) AS players ORDER BY numberOfPlayers DESC ``` which again doesn’t compile: ``` SyntaxException: Aggregation expressions must be listed in the RETURN clause to be used in ORDER BY ``` I eventually found [a post by Andres](http://stackoverflow.com/questions/12269009/returning-two-aggregates-in-a-single-cypher-query?rq=1) where he explains that you need to split the query into two and make use of http://docs.neo4j.org/chunked/milestone/query-with.html if you want to make use of two aggregation expressions. I ended up with the following query which does the job: ``` START player = node:players('name:*') MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team WITH DISTINCT team, COLLECT(player.name) AS players MATCH player-[:missed_penalty_in]-game, player-[:played|subbed_on]-stats-[:in]-game, stats-[:for]-team WITH DISTINCT team, COUNT(player) AS numberOfPlayers, players RETURN team.name, players ORDER BY numberOfPlayers DESC ``` ``` +---------------------------------------------------------------------------------+ | team.name | players | +---------------------------------------------------------------------------------+ | "Manchester United" | ["Wayne Rooney","Javier Hernández","Robin Van Persie"] | | "Chelsea" | ["Frank Lampard","Lucas Piazon"] | | "Liverpool" | ["Steven Gerrard"] | | "Manchester City" | ["David Silva"] | | "Newcastle United" | ["Papiss Demba Cisse"] | | "Queens Park Rangers" | ["Adel Taarabt"] | | "Stoke City" | ["Jonathan Walters"] | | "Arsenal" | ["Mikel Arteta"] | | "West Bromwich Albion" | ["Shane Long"] | +---------------------------------------------------------------------------------+ 9 rows ```
Shard2 (laksa)
Root Hash13626504119187361002
Unparsed URLcom,markhneedham!www,/blog/2013/02/24/neo4jcypher-combining-count-and-collect-in-one-query/ s443