Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-19-2021 07:42 AM
I have several nodes of the following type: label - ServiceDate, property - date
(:ServiceDate {date: "2018-02-13"} )
I like to write a query that returns the distinct years and number of nodes in each year. The query should return the following:
2016 2017 2018 2019 2020
100 30 200 300 240
the following query gives me the required detail for a particular year :
MATCH (sd:ServiceDate)
WITH date(sd.date) as sd1
WHERE sd1.year = 2018
RETURN count(sd)
I need help on the query that will return for all the years from 2016 to 2020.
appreciate any help.
Solved! Go to Solution.
04-19-2021 07:51 AM
Hello @nswamy.lakshman and welcome to the Neo4j community
For each year of your database:
MATCH (sd:ServiceDate)
RETURN date(sd.date).year AS year, count(sd) AS nbNodes
Between 2016 and 2020:
UNWIND range(2016, 2021) AS year
MATCH (sd:ServiceDate)
WHERE date(sd.date).year = year
RETURN year, count(sd) AS nbNodes
OR
MATCH (sd:ServiceDate)
WITH date(sd.date).year AS year, count(sd) AS nbNodes
WHERE year IN range(2016, 2021)
RETURN year, nbNodes
Regards,
Cobra
04-19-2021 07:51 AM
Hello @nswamy.lakshman and welcome to the Neo4j community
For each year of your database:
MATCH (sd:ServiceDate)
RETURN date(sd.date).year AS year, count(sd) AS nbNodes
Between 2016 and 2020:
UNWIND range(2016, 2021) AS year
MATCH (sd:ServiceDate)
WHERE date(sd.date).year = year
RETURN year, count(sd) AS nbNodes
OR
MATCH (sd:ServiceDate)
WITH date(sd.date).year AS year, count(sd) AS nbNodes
WHERE year IN range(2016, 2021)
RETURN year, nbNodes
Regards,
Cobra
04-19-2021 08:21 AM
appreciate your prompt reply.
04-19-2021 08:24 AM
Does it solve your problem?
04-19-2021 09:08 AM
yes.. does address my needs.
All the sessions of the conference are now available online