cassandra cql order by实验 1create table simplex.playlists (2 id uuid,3 title text,4 num int,5 album text,6 artist text,7 song_id uuid,8 primary key (id,title,num)9 );1select * from simplex.playlists where id=2cc9ccb7-6221-4ccb-8387-f22b6a
cassandra cql order by实验
1create table simplex.playlists (2 id uuid,3 title text,4 num int,5 album text,6 artist text,7 song_id uuid,8 primary key (id,title,num)9 );1select * from simplex.playlists where id=2cc9ccb7-6221-4ccb-8387-f22b6a1b354d order by title desc;1搜索成功1select * from simplex.playlists where id=2cc9ccb7-6221-4ccb-8387-f22b6a1b354d order by num desc;1搜索异常order by currently only support the ordering of columns following their declared order in the primary key1select * from simplex.playlists order by title desc;1异常:order by is only supported when the partition key is restricted by an eq or an in.1select * from simplex.playlists where num=1 order by title desc;1异常:primary key part num cannot be restricted (preceding part title is either not restricted or by a non-eq relation1select * from simplex.playlists where title='la petite tonkinoise' order by title desc;1异常:order by is only supported when the partition key is restricted by an eq or an in.1select * from simplex.playlists where id=2cc9ccb7-6221-4ccb-8387-f22b6a1b354d order by id desc;1异常:order by is currently only supported on the clustered columns of the primary key, got id1select * from simplex.playlists where title='la petite tonkinoise' order by num desc;1异常:order by is only supported when the partition key is restricted by an eq or an in.1通过以上实验可以得出cassandra cql order by 字段必须是复合主键的第二个字段,并且需要where后跟上第一个字段的条件判断。1另外:clustering order010203 04 05 06 07 08 09 10 11 12 官方说明 13 if the table has been defined without any specific clustering order, then then allowed orderings are the order induced by the clustering key and the reverse of that one. 14 otherwise, the orderings allowed are the order of the clustering order option and the reversed one. 15 16
用法是 :with clustering order by( title desc) 跟在建表语句后面。目的是改变数据存储排序方式