I have a campaign node which has a relationship with Picture node.
I'm trying to get , in each campaign that the query finds , a random picture which connected to it.
I managed to get a random picture to a single campaign, but if I want to each campaign a connected picture output, I'm having trouble to do it.
This is an example to get a single picture to within a campaign.
MATCH (campaign:Campaign)-[]-(picture:Picture) where
campaign.id="1429184083571" or campaign.id='1429182615443'
WITH picture, rand() AS r,campaign
ORDER BY r
RETURN campaign,picture
limit 1
How can i get an output for each campaign a connected random picture ?
This should work:
MATCH (campaign:Campaign)-[]-(picture:Picture)
with campaign, collect(picture) as pictures
RETURN campaign,pictures[toInt(rand()*size(pictures))]
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.