【问题标题】:CQL: comparing two column valuesCQL:比较两列值
【发布时间】:2014-05-10 19:00:15
【问题描述】:

我有一个这样的TABLE

    id   | expected | current
   ------+----------+--------
     123 |    25    |   15
     234 |    26    |   26
     345 |    37    |   37

现在我想选择所有ids,其中current 等于expected。在 SQL 中,我会这样做:

SELECT id FROM myTable WHERE current = expected;  

但在 CQL 中它似乎是无效的。我的cqlsh 会返回这个:

no viable alternative at input 'current'

是否有有效的 CQL 查询来实现这一点?

已编辑 根据 CQL-Docs 它应该可以工作,但它没有......这就是文档所说的:

<selectWhereClause> ::= <relation> ( "AND" <relation> )*
                      | <term> "IN" "(" <term> ( "," <term> )* ")"

<relation> ::= <term> <relationOperator> <term>

<relationOperator> ::= "=" | "<" | ">" | "<=" | ">="

<term> ::= "KEY"
         | <identifier>
         | <stringLiteral>
         | <integer>
         | <float>
         | <uuid>
         ;

【问题讨论】:

    标签: cassandra cql cqlsh


    【解决方案1】:

    我使用了错误的文档。我正在使用 CQL3 并阅读 CQL2 的文档。 正确的文档说:

    <where-clause> ::= <relation> ( AND <relation> )*
    
    <relation> ::= <identifier> <op> <term>
                 | '(' <identifier> (',' <identifier>)* ')' <op> '(' <term> (',' <term>)* ')'
                 | <identifier> IN '(' ( <term> ( ',' <term>)* )? ')'
                 | TOKEN '(' <identifier> ( ',' <identifer>)* ')' <op> <term>
    

    所以它不是一个有效的查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多