开发者

How to automatically backup a ratio of a table based on one column?

I want to automatically backup a database so I 开发者_高级运维have two databases, one with all data and the other with a ratio of each table -i.e. 20%- based on a column.


Here's my first try.

create table t1 (
id integer primary key,
val integer not null);

create table t2 (
id integer primary key,
val integer not null);

insert into t1 values (1,1000);
insert into t1 values (2,1000);
insert into t1 values (3,1000);
insert into t1 values (4,1000);
insert into t1 values (5,1000);
insert into t1 values (6,1000);
insert into t1 values (7,1000);
insert into t1 values (8,1000);
insert into t1 values (9,1000);
insert into t1 values (10,1000);
insert into t1 values (11,1000);

insert into t2
select id, val
from t1
where (val >= 1000) 
  and (rownum <= cast((0.2 * (select count(*) from t1)) as integer));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜