【发布时间】:2021-12-24 15:01:47
【问题描述】:
表架构如下:
image_id | activity_time | image_location
----------+---------------+--------------------
243 | 2021-10-22 | remotelocation_243
243 | 2021-10-25 | remotelocation_243
88 | 2021-10-12 | remotelocation_88
215 | 2021-10-20 | remotelocation_215
215 | 2021-10-21 | remotelocation_215
215 | 2021-10-22 | remotelocation_215
215 | 2021-10-25 | remotelocation_215
80 | 2021-10-12 | remotelocation_80
248 | 2021-10-20 | remotelocation_248
248 | 2021-10-21 | remotelocation_248
248 | 2021-10-22 | remotelocation_248
248 | 2021-10-25 | remotelocation_248
234 | 2021-10-20 | remotelocation_234
234 | 2021-10-21 | remotelocation_234
234 | 2021-10-22 | remotelocation_234
234 | 2021-10-25 | remotelocation_234
11 | 2021-10-12 | remotelocation_11
501 | 2021-10-22 | remotelocation_501
1 | 2021-10-12 | remotelocation_1
509 | 2021-10-22 | remotelocation_509
78 | 2021-10-12 | remotelocation_78
96 | 2021-10-12 | remotelocation_96
539 | 2021-10-22 | remotelocation_539
我想根据activity_time获取最后N条记录。我读到以下内容:
Cassandra + Fetch the last records using in query
Order latest records by timestamp in Cassandra
但是,我发现它需要某种 where 子句才能从 order by 中获取结果。
我只想做这样的事情:
select * from table_name order by activity_time desc limit 20;
非常感谢任何帮助。提前致谢。
【问题讨论】:
-
什么是主键定义?
-
主键 - image_id.
-
看起来不是这样的。 Cassandra 中的 PK 是独一无二的。我看到多个 248、215、243 等。
标签: python cassandra cassandra-3.0