insert all into people (person_id,first_name,last_name) values(person_id,first_name,last_name)into people (first_name,last_name,parent_id) values(child1,last_name,person_id)into people (first_name,last_name,parent_id) values(child2,last_name,person_id)into people (first_name,last_name,parent_id) values(child3,last_name,person_id)into people (first_name,last_name,parent_id) values(child4,last_name,person_id)into people (first_name,last_name,parent_id) values(child5,last_name,person_id)into people (first_name,last_name,parent_id) values(child6,last_name,person_id)
select person_id,first_name,last_name,child1,child2,child3,child4,child5,child6
from demo_perple;
多表插入
insert allinto parents (person_id,first_name,last_name) values(person_id,first_name,last_name)into children (first_name,last_name,parent_id) values(child1,last_name,person_id)into children (first_name,last_name,parent_id) values(child2,last_name,person_id)into children (first_name,last_name,parent_id) values(child3,last_name,person_id)into children (first_name,last_name,parent_id) values(child4,last_name,person_id)into children (first_name,last_name,parent_id) values(child5,last_name,person_id)into children (first_name,last_name,parent_id) values(child6,last_name,person_id)
select children ,first_name,last_name,child1,child2,child3,child4,child5,child6
from demo_perple;
条件插入
insert allwhen 1=1 theninto people (person_id,first_name,last_name) values(person_id,first_name,last_name)when child1 is not null then into people (first_name,last_name,parent_id) values(child1,last_name,person_id)when child2 is not null then into people (first_name,last_name,parent_id) values(child2,last_name,person_id)when child3 is not null then into people (first_name,last_name,parent_id) values(child3,last_name,person_id)when child4 is not null then into people (first_name,last_name,parent_id) values(child4,last_name,person_id)when child5 is not null then into people (first_name,last_name,parent_id) values(child5,last_name,person_id)when child6 is not null then into people (first_name,last_name,parent_id) values(child6,last_name,person_id)
select children ,first_name,last_name,child1,child2,child3,child4,child5,child6
from demo_perple;