简体   繁体   中英

How to find out which of the games happened on Mondays only?

I have tried 2 codes, the first one hasn't worked, while the second has. I basically have to display how many games were played on Mondays and show the teams that played them.

MATCH (t:Teams)
WHERE date({year:2019, month: 1 }) > t.Date <= date({year:2018, month:12})
RETURN t.HomeTeam AS HomeTeam,
    t.AwayTeam AS AwayTeam,
    t.Date AS Date

The result is: (No changes, no records) - nothing

MATCH (t:Teams)
WITH [item in split(t.Date, "/") | toInteger(item)] AS dateComponents
WITH ({day: dateComponents[0], month: dateComponents[1], year: dateComponents[2]}).dayOfWeek AS date
WHERE date = 1
RETURN COUNT(*)

The result is: Count(*) 0

I think there may be a couple of things going on in your first query. The date matching line

WHERE date({year:2019, month: 1 }) > t.Date <= date({year:2018, month:12})

is looking for a date that is less than 20190101 and less than or equal to 20181201. If you are actually looking for a date between those two values you need to change the operator to greather than equals for 201801.

That said, if Date is actually a string then the date comparison will not work either.

In your second query, it looks like you decided that Date was indeed a string and you split it up but still did not get any results. Although you break the date string up into its components you did not supply the date() function around your date components in this line...

WITH ({day: dateComponents[0], month: dateComponents[1], year: dateComponents[2]}).dayOfWeek AS date

Try this for your second query.

MATCH (t:Teams)
WITH [item in split(t.Date, "/") | toInteger(item)] AS dateComponents
WITH date({day: dateComponents[0], month: dateComponents[1], year: dateComponents[2]}).dayOfWeek AS date
WHERE date = 1
RETURN COUNT(*)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM