Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Select Cassandra错误-仅当分区键受EQ或IN限制时才支持按顺序排序_Select_Cassandra_Sql Order By_Cql - Fatal编程技术网

Select Cassandra错误-仅当分区键受EQ或IN限制时才支持按顺序排序

Select Cassandra错误-仅当分区键受EQ或IN限制时才支持按顺序排序,select,cassandra,sql-order-by,cql,Select,Cassandra,Sql Order By,Cql,这是我正在创建的表格,这个表格包含了上一届蒙代尔杯的球员信息 CREATE TABLE players ( group text, equipt text, number int, position text, name text, day int, month int, year int, club text, liga text, capitan text, PRIMARY key (name, day, month, year)); 执行以下查询时

这是我正在创建的表格,这个表格包含了上一届蒙代尔杯的球员信息

CREATE TABLE players ( 
      group text, equipt text, number int, position text, name text,
      day int, month int, year int, 
      club text, liga text, capitan text,
PRIMARY key (name, day, month, year));
执行以下查询时:

从担任选拔队队长的最老球员那里获得5个名字

我的问题是:

SELECT name FROM players WHERE captain='YES' ORDER BY year DESC LIMIT 5;
我得到了这个错误:

仅当分区键受EQ或IN限制时才支持排序方式

我认为这是我正在创建的表的一个问题,但我不知道如何解决它


谢谢。

您试图运行的查询的表定义不正确

您已经用分区键“name”、集群列“day”、“month”、“year”和各种其他列定义了一个表

在Cassandra中,所有SELECT查询都必须使用EQ或In指定分区键。您可以使用SQL中常用的相等和不相等运算符包含部分或全部集群列

必须按照定义的顺序包含群集列。ORDERBY子句只能包含EQ尚未指定的集群列,同样是按照它们定义的顺序

例如,您可以编写查询

select * from players where name = 'fiticida' and day < 5 order by month desc;
但不是

select * from players where name = 'fiticida' and year = 2017;
其中不包括“日”或“月”

而不是

select * from players where name = 'fiticida' and day = 5 order by year desc;
不包括“月”

是有关SELECT查询的正式文档


为了满足您的查询,表需要

  • EQ或“captain”中指定的分区键将起作用
  • 使用最左边集群列的ORDERBY子句:在主键定义中,将“年”放在“月”和“日”的左边
select * from players where name = 'fiticida' and day = 5 order by year desc;