Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Select 如何按不同的列选择最后一个时间戳?_Select_Cassandra_Cql - Fatal编程技术网

Select 如何按不同的列选择最后一个时间戳?

Select 如何按不同的列选择最后一个时间戳?,select,cassandra,cql,Select,Cassandra,Cql,假设有这样的表: | user_id | location_id | datetime | other_field | | ------- | ----------- | ------------------- | ----------- | | 12 | 1 | 2020-02-01 10:00:00 | asdqwe | | 12 | 1 | 2020-02-01 10:30:00 | asdqwe

假设有这样的表:

| user_id | location_id | datetime            | other_field |
| ------- | ----------- | ------------------- | ----------- |
| 12      | 1           | 2020-02-01 10:00:00 | asdqwe      |
| 12      | 1           | 2020-02-01 10:30:00 | asdqwe      |
| 12      | 2           | 2020-02-01 10:40:00 | asdqwe      |
| 12      | 2           | 2020-02-01 10:50:00 | asdqwe      |
| 13      | 1           | 2020-02-01 10:10:00 | asdqwe      |
| 13      | 1           | 2020-02-01 10:20:00 | asdqwe      |
| 14      | 3           | 2020-02-01 09:00:00 | asdqwe      |
我想选择每个不同的
user\u id
location\u id
的最后一个
datetime
。这就是我想要的结果:

| user_id | location_id | datetime            | other_field |
| ------- | ----------- | ------------------- | ----------- |
| 12      | 1           | 2020-02-01 10:30:00 | asdqwe      |
| 12      | 2           | 2020-02-01 10:50:00 | asdqwe      |
| 13      | 1           | 2020-02-01 10:20:00 | asdqwe      |
| 14      | 3           | 2020-02-01 09:00:00 | asdqwe      |
以下是表格说明:

创建表mykeyspace.mytable(
用户id int,
位置_idint,
日期时间戳,
其他字段文本,
主键((用户id、位置id、其他字段)、日期时间)
)使用群集顺序(日期时间ASC)
并读取_repair_chance=0.0
和dclocal\u read\u repair\u chance=0.1
gc_grace_秒=864000
布卢姆过滤器概率=0.01
和缓存={'keys':'ALL','rows\u per\u partition':'NONE'}
和注释=“”
AND compression={'class':'org.apache.cassandra.db.compression.SizeTieredCompactionStrategy','max_threshold':32','min_threshold':4}
压缩={'chunk\u length\u in_kb':64,'class':'org.apache.cassandra.io.compress.LZ4Compressor'}
并且默认的\u time\u to\u live=0
和推测性_重试='99百分位'
最小索引间隔=128
最大指数间隔=2048
和crc检查机会=1.0
cdc=假;
对于这些东西,CQL已经(在Cassandra 3.6+IIRC中提供)。但要在表上使用,需要将表定义更改为
集群顺序BY(datetime DESC)
,然后可以编写:

select * from prospacedb.quarter_utilisation per partition limit 1;

并为您拥有的每个分区键获取带有最新时间戳的行。

您可以添加
描述表xxxx的输出吗?嗨@AlexOtt,我只是在问题中写下描述