xxxxxxxxxx
-- INIT database
CREATE TABLE devicelog (
id int,
yourdatecolumn date,
devicetype VARCHAR2(255)
);
insert into devicelog values (1,sysdate,'thing');
insert into devicelog values (1,sysdate,'thing');
insert into devicelog values (1,sysdate-2,'thing');
insert into devicelog values (2,sysdate,'thing 2');
insert into devicelog values (3,sysdate,'thing 3');
insert into devicelog values (3,sysdate,'thing 3');
insert into devicelog values (3,sysdate-3,'thing 3');
select * from (
select id,yourdatecolumn,devicetype, row_number() over(partition by id, yourdatecolumn order by yourdatecolumn asc) as rn
from devicelog
) foo
where rn=1;
ID | YOURDATEC | DEVICETYPE | RN |
---|---|---|---|
1 | 29-JAN-25 | thing | 1 |
1 | 31-JAN-25 | thing | 1 |
2 | 31-JAN-25 | thing 2 | 1 |
3 | 28-JAN-25 | thing 3 | 1 |
3 | 31-JAN-25 | thing 3 | 1 |