这是我正在创建的表,该表包含有关上次参加 Mundial 杯的球员的信息。
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));
执行以下查询时:
Obtain 5 names from the oldest players that were captain of the selection team
这是我的查询:
SELECT name FROM players WHERE captain='YES' ORDER BY year DESC LIMIT 5;
我收到此错误:
Order By only supported when partition key is restricted by EQ or IN
我认为是我创建的表有问题,但我不知道如何解决。
谢谢。
最佳答案
您尝试运行的查询的表定义不正确。
您已经定义了一个包含分区键“name”、聚集列“day”、“month”、“year”和各种其他列的表。
在 Cassandra 中,所有 SELECT 查询都必须使用 EQ 或 IN 指定分区键。您可以使用您在 SQL 中使用的等式和不等式运算符来包含部分或全部聚类列。
聚类列必须按它们定义的顺序包含。 ORDER BY 子句只能包含尚未由 EQ 指定的聚类列,同样按照它们定义的顺序。
例如,您可以编写查询
select * from players where name = 'fiticida' and day < 5 order by month desc;
或者
select * from players where name = 'fiticida' and day = 10 and month > 2 order by month asc;
但不是
select * from players where name = 'fiticida' and year = 2017;
不包括“日”或“月”
并不是
select * from players where name = 'fiticida' and day = 5 order by year desc;
其中不包括“月”。
Here是关于 SELECT 查询的官方文档。
为了满足您的查询,该表需要
关于select - Cassandra 错误 - 仅当分区键受 EQ 或 IN 限制时才支持 Order By,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46921455/