0

In mysql if would like to index some rows by for example by time I would index the column time and every time I would enter new data it would get indexed automatically and it would look like that if would like to retrieve the data using that index

data| time
1| 22-6-2013
2| 21-5-2013
3| 20-4-2013
  • How could I do the same in cassandra?

One way I could think of is by creating an object with a primary index (not using uuid) looking like that 20-4-2013 and then literally search through every date beginning at for example 22-6-2013 (the highest) until I find an object or row.

  • Is there another way of doing that?
4

1 回答 1

0

您可以创建一个“CompositeKey”表,格式如下:

CREATE TABLE timetable(
unique_id varchar,
time timestamp,
other_data varchar,
PRIMARY KEY (unique_id, time)
);

然后您可以使用以下查询:

select * from timetable order by time desc;

或者

select * from timetable time > '2012-11-24' order by time desc;

您也可以订购“ascendent”,只需将“desc”更改为“asc”...

于 2013-07-25T09:26:47.413 回答