天天看点

从一个或几个table中获取数据插入到另一个table中

Table  target:

-----------------------------------------------

ID                        char(32)             PK

description          varchar(100)      null

value                   var                     not null

update_time       date                   not null

Table sourceA

----------------------------------------------

sourceID             char(32)             PK

flag                     char(1)               not null

Table sourceB

----------------------------------------------

sourceID             char(32)             PK

value                   varchar(1)          not null

insert into target(

    ID,

    description,

    value,

    update_time

)

select

s1.sourceID,

case when s1.flat = 'Y' then 'active'

        when s1.flat = 'N' then 'deactive'

        end,

s2.value,

current_timestamp

from sourceA s1, sourceB s2;