特定 Oracle SQL 查询(加入、联合..?)

Specific Oracle SQL Query (Join, Union..?)

我有一个查询语句的问题。我只是没弄清楚...

与下面Select

Select
    dt_root.parentid, dt_root.dataid, dt_root.name, dt_root.modifydate
from
    dtree dt_root
where
    dt_root.parentid in (18524213,18523767)

我明白了 table:

有没有可能,当我在 .dwg 和 .pdf 中有相同的文件时,我将排在一行中,如下所示:

DATAID_DWG | NAME_DWG | MDFDATE_DWG | DATAID_PDF | NAME_PDF | MDFDATE_PDF

我尝试了很多不同的连接,但我不明白。

感谢您的帮助!

不确定你是否想要

  • INNER JOIN 表示仅显示具有两个文件名
  • 的行
  • FULL JOIN,在那种情况下,每一侧都有手柄NULL

内连接

SELECT 
       dt_A.DataID     AS DATAID_DWG,
       dt_A.Name       AS NAME_DWG,
       dt_A.ModifyDate AS MDFDATE_DWG,
       dt_B.DataID     AS DATAID_PDF,
       dt_B.Name       AS NAME_PDF,
       dt_B.ModifyDate AS MDFDATE_PDF
FROM 
           dtree dt_A
INNER JOIN dtree dt_B
       ON substr(dt_A.name, 0, length(dt_A.name)-4) 
        = substr(dt_B.name, 0, length(dt_B.name)-4)
      AND dt_A.DATAID <> dt_B.DATAID

WHERE substr (dt_A.name, -4) = '.dwg' 
  AND substr (dt_B.name, -4) = '.pdf' 

FULL JOIN:我展示了一些部分空值处理。您需要安排其余字段。

SELECT 
       CASE 
           WHEN dt_A NOT NULL THEN dt_A.Name
           ELSE '' 
       END AS   DATAID_DWG,
       NAME_DWG ,
       MDFDATE_DWG,
       DATAID_PDF,
       NAME_PDF,
       MDFDATE_PDF
FROM 
          dtree dt_A
FULL JOIN dtree dt_B
       ON substr(dt_A.name, 0, length(dt_A.name)-4) 
        = substr(dt_B.name, 0, length(dt_B.name)-4)
      AND dt_A.DATAID <> dt_B.DATAID

WHERE substr (dt_A.name, -4) = '.dwg' 
  AND substr (dt_B.name, -4) = '.pdf'