如果一行早于某个时间戳,则使用SQL删除对

如果一行早于某个时间戳,则使用SQL删除对,sql,oracle,Sql,Oracle,我有一个包含两列的表: match_id varchar2(30) timestamp 匹配id的格式为整数[A | B],例如1234.A、1234.B、1235.A或1235.B。在同一整数上具有匹配id的行称为一对,因此1234.a和1234.B是一对,而1235.a和1235.B是另一对 要求是删除所有对,如果该对中的一行早于某个时间戳。数据库是Oracle 11.2或更高版本 我不擅长SQL,因此非常感谢您的帮助。不是理想的数据模型!两位信息,整数和A | B部分,存储在一列中 我无

我有一个包含两列的表:

match_id varchar2(30)
timestamp
匹配id的格式为整数[A | B],例如1234.A、1234.B、1235.A或1235.B。在同一整数上具有匹配id的行称为一对,因此1234.a和1234.B是一对,而1235.a和1235.B是另一对

要求是删除所有对,如果该对中的一行早于某个时间戳。数据库是Oracle 11.2或更高版本


我不擅长SQL,因此非常感谢您的帮助。

不是理想的数据模型!两位信息,整数和A | B部分,存储在一列中

我无法测试下面的解决方案没有提供测试数据,但类似的方法应该可以工作:

delete from your_table_name
where substr(match_id, 1, instr(match_id, '.')) 
         in (
               select substr(match_id, 1, instr(match_id, '.')) 
               from   your_table_name
               where  timestamp_column <= :input_timestamp_value
            )
;

请看下面的

create table test_1
匹配id varchar230, ts时间戳 ;

以获取表的内容

select * from test_1;
1234.A 2017年1月9日上午08.55.24.000000000 1234.B 2016年12月30日上午08.56.02.000000000 1235.A 2016年12月20日上午08.56.02.000000000 1235.B 2016年12月10日上午08.56.02.000000000

将删除时间戳小于当前时间戳30的所有对

delete test_1 where substr(match_id,1,instr(match_id,'.')-1) in (select substr(match_id,1,instr(match_id,'.')-1) from test_1 where ts < current_timestamp-30);

select * from test_1;
1234.A 2017年1月9日上午08.55.24.000000000 1234.B 2016年12月30日上午08.56.02.000000000

delete test_1 where substr(match_id,1,instr(match_id,'.')-1) in (select substr(match_id,1,instr(match_id,'.')-1) from test_1 where ts < current_timestamp-30);

select * from test_1;