Home > database >  According to the sal field divided the same person into multiple data
According to the sal field divided the same person into multiple data

Time:10-02

The split into below

At first the idea is to create a backup table, and then the backup table update into 50%, the original table update into 50%, then the backup table data is copied to the original list

CodePudding user response:

The UPDATE 50% first, and then insert into a full table

CodePudding user response:

 CREATE TABLE test_t (ID, name, sal) AS 
SELECT 1, 'a', 2000 FROM dual
UNION ALL SELECT 2, 'b', 3000 FROM dual
UNION ALL SELECT 3, 'c', 2500 FROM dual;
- SELECT * FROM test_t;
INSERT INTO test_t t1 SELECT * FROM test_t t2;
COMMIT;
The UPDATE test_t SET sal=0.5 * sal;
COMMIT;

CodePudding user response:

With tb1 as
(SELECT 1 fd1 and fd2 'a', 2000 fd3
The FROM dual
UNION ALL
SELECT 2 fd1 and fd2 'b', 3000 fd3
The FROM dual
UNION ALL
SELECT 3 fd1 and fd2 'c', 2500 fd3
The FROM dual),
Tb2 as
(select 2 fd1 from dual union all select 2 fd1 from dual)
A.f a.f select a.f d1, d2, d3/b. the from d1 tb1 a, tb2 b

CodePudding user response:

- 1. The build table
The create table test_A
(
ID varchar (20),
The name varchar (20),
Sal int

);
- 2. Insert test data
Insert into test_A values (' 1 ', 'a', 2000);
Insert into test_A values (' 2 ', 'b', 3000);
Insert into test_A values (' 3 ', 'c', 2500);
- 3. The percentage processing, and in the name field to spell a test
Insert into test_A (select the 'test' | | ID, name, sal * 0.5 from test_A union all select 'test' | | ID, name, sal * 0.5 from test_A)
- 4. Delete the original data
Select * from test_A t where instr (t.n ame, 'test')=0
- 5. Behind the name of the test remove
The update test_A t set name=substr (t.n ame, 5, length (t.n ame));
  • Related