如何在一个表中连接五个表?

时间:2014-08-21 10:47:24

标签: database oracle join

我有5个表是设备日志,表是相同的,只是按月划分,您需要将它们粘合到一个表中并使用DEVICES_ACTIVE将其连接到主键。

     1. Table DEVICES_ACTIVE
         DEVICE_ID  NUMBER(38,0)    PK

     2. Table DJ_05_2014
        DEVICE_ID NUMBER(38,0) PK
        START TIMESTAMP
        STOP TIMESTAMP

     3. Table DJ_06_2014
        DEVICE_ID NUMBER(38,0) PK
        START TIMESTAMP
        STOP TIMESTAMP

     4. Table DJ_07_2014
        DEVICE_ID NUMBER(38,0) PK
        START TIMESTAMP
        STOP TIMESTAMP
......................

1 个答案:

答案 0 :(得分:1)

select ...
  from devices_active
  join (select ... from dj_07_2014 union all
        select ... from dj_06_2014 union all
        select ... from dj_05_2014
       ) using(device_id);