I am new to cassandra and have query reg data model.
Can someone tell me how to write select query to return first record of each minute ? First record here refers to first record of each minute (based on seconds). Please see example below. My System is going to regulary receive data for every 5 seconds from device. My Table structure is going to be like this.
CREATE TABLE device (
deviceId text,
datetime timestamp,
temp float,
volt float,
PRIMARY KEY (deviceId, datetime)
) WITH CLUSTERING ORDER BY (datetime DESC);
Is it possible to extract the datetime in select query , process it and find the first record of each minute?
insert into device (deviceId,datetime,temp,volt)
values ('device123','2018-10-10 5:10:00+0000',0.12,6.7);
insert into device (deviceId,datetime,temp,volt)
values ('device123','2018-10-10 5:10:05+0000',3.12,61.7);
insert into device (deviceId,datetime,temp,volt)
values ('device123','2018-10-10 5:10:10+0000',2.12,16.7);
insert into device (deviceId,datetime,temp,volt)
values ('device123','2018-10-10 5:10:15+0000',1.12,26.7);
insert into device (deviceId,datetime,temp,volt)
values ('device123','2018-10-10 5:11:20+0000',4.12,11.7);
insert into device (deviceId,datetime,temp,volt)
values ('device123','2018-10-10 5:11:25+0000',5.12,12.7);
insert into device (deviceId,datetime,temp,volt)
values ('device123','2018-10-10 5:11:30+0000',6.12,23.7);
insert into device (deviceId,datetime,temp,volt)
values ('device123','2018-10-10 5:11:35+0000',7.12,126.7);
My Query should give me the result like this:
- For 10th minute, second=00 temp=0.12, volt = 6.7
- For 11th minute,second=20 temp=4.12, volt = 11.7
Can you provide suggestions as to how I can achive this in cassandra?