我有一个查询声明的问题。我只是没有把它弄好......
使用以下选择
Select
dt_root.parentid, dt_root.dataid, dt_root.name, dt_root.modifydate
from
dtree dt_root
where
dt_root.parentid in (18524213,18523767)
我得到这张桌子:
是否有可能,当我在.dwg和.pdf中有相同的文件时,我会在一行中,如下所示:
DATAID_DWG | NAME_DWG | MDFDATE_DWG | DATAID_PDF | NAME_PDF | MDFDATE_PDF
我尝试了很多不同的联接,但我没有得到它。
感谢您的帮助!
答案 0 :(得分:2)
不确定是否需要
INNER JOIN
表示仅显示具有文件名FULL JOIN
,在这种情况下,每边都处理NULL
。INNER JOIN
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'