2016-10-19 46 views
1

創建表:caassandra:在同一列中的多個條件

CREATE TABLE notifications (
    id uuid PRIMARY KEY, 
    user_id bigint, 
    received_datetime timestamp, 
); 

cqlsh:

select count(*) 
    from notifications 
    where received_datetime >='2016-10-11 00:00:00' 
    and received_datetime >='2016-10-18 00:00:00' 
    ALLOW FILTERING; 

錯誤了: -

InvalidRequest: Error from server: code=2200 [Invalid query] message="More than one restriction was found for the start bound on received_datetime" 

回答

1

我猜你真正想要的是下面的查詢:

select count(*) from notifications 
    where received_datetime >='2016-10-11 00:00:00' 
    and received_datetime <='2016-10-18 00:00:00' 
    ALLOW FILTERING; 

否則,您可以通過挑選更嚴格的人合併兩個下界條件爲一個:

select count(*) from notifications 
    where received_datetime >= '2016-10-18 00:00:00' 
    ALLOW FILTERING; 
+0

我錯過了這一點感謝。 –

+0

您在上面使用ALLOW FILTERING進行的查詢是Cassandra中的反模式。這將導致整個集羣的分散收集操作,這將非常緩慢,並且很可能超時並且有任何合理的大量數據。你應該改變你的表結構來滿足你所要求的查詢。這意味着要設置一個不同的分區和主鍵來回答這個查詢,除非你知道id,在這種情況下,你可以將received_datetime作爲一個集羣列並對其執行範圍查詢。 – bechbd

相關問題