【问题标题】:Neo4j cypher: Limiting returned results by an expressionNeo4j cypher:通过表达式限制返回的结果
【发布时间】:2015-09-16 19:08:35
【问题描述】:

我正在尝试将我的结果限制在一个随机集合中。到目前为止,我有这个查询工作:

MATCH (n),
RETURN n, rand() as random
ORDER BY random
LIMIT 25

但是,在以下两个密码示例中,尝试用随机数替换 LIMIT 25 时出现问题:

MATCH (n)
RETURN n, rand() as random, toInt(rand()*25) as randCount
ORDER BY random
LIMIT randCount

在上面,删除 LIMIT 会正确返回 randcount

WITH toInt(rand()*25) as randCount
MATCH (n)
RETURN n, rand() as random
ORDER BY random
LIMIT randCount

我的直接想法是 Cypher 不(还)支持使用变量/表达式来限制结果......或者我做错了 ;-)

【问题讨论】:

  • 这是计划开发但尚未完成的东西:)
  • 听起来很棒@MichaelHunger!

标签: neo4j cypher


【解决方案1】:

我试过你的例子,你是对的,密码不支持变量作为 LIMIT 的参数。

这是您正在寻找的证据:

我开始了上面的查询:

PROFILE 
MATCH (n)
RETURN n, rand() as random, toInt(rand()*25) as randCount
ORDER BY random
LIMIT 1

结果如下:

正如您在配置文件结果中看到的那样,LIMIT 在 randCount 受到影响之前执行,因此当您执行时,LIMIT randCountrandCount 不存在,就像您创建的所有其他变量一样。

即使在Projection部分做了random,它的值也不会立即影响到randCount。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-15
    • 2018-05-14
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 2019-08-22
    • 2014-12-21
    • 1970-01-01
    相关资源
    最近更新 更多