Search code examples
cassandracassandra-2.0cqlcql3phantom-dsl

CQL: Select all rows, distinct partition key


I have a table

    CREATE TABLE userssbyprofit (
    userid text,
    profit double,
    dateupdated timeuuid,
    PRIMARY KEY (userid, profit, dateupdated)
) WITH CLUSTERING ORDER BY (profit DESC, dateupdated DESC)

Userid can be used to lookup the full user details in another table. This table will provide a history of the users profits. Taking the most recent one to find their current profit amount.

How do I retrieve the 10 most profitable users with their profit amount. I want it to be distinct based on the userID

Thanks.


Solution

  • You need to create one more table or view which have only user id and profit . New table or view will have user id order by profit with desc order .