如何为CQLSH中的任何列运行SELECT DISTINCT?

时间:2018-05-07 12:38:20

标签: cassandra cqlsh

每当我尝试运行SELECT DISTINCT %column_name from %table_name时,我都会收到

InvalidRequest: Error from server: code=2200 [Invalid query] message="SELECT DISTINCT queries must only request partition key columns and/or static columns (not specified %column_name)"

1 个答案:

答案 0 :(得分:1)

您只能在SELECT DISTINCT列上投放partition key。例如,如果您的架构如下所示:

CREATE TABLE artist (
    id int PRIMARY KEY,
    band_name text,
    name text,
    role text
);

然后查询将是:

SELECT DISTINCT id FROM artist;