给予下面的表格我需要从NAT_DASH_AUD_ELEMENTO_WORKFLOW_LOC_008
中获取所有记录,并为每行从NAT_DASH_AUD_ELEMENTO_WORKFLOW_007
中获取,
AuditData <= NAT_DASH_AUD_ELEMENTO_WORKFLOW_LOC_008.AuditData
and ID_ELEMENTO_008 = ID_007
使用join不能做到这一点,因为代码将是,并且不允许内部条件
select * from
NAT_DASH_AUD_ELEMENTO_WORKFLOW_LOC_008
INNER JOIN
(SELECT * FROM NAT_DASH_AUD_ELEMENTO_WORKFLOW_007
WHERE
NAT_DASH_AUD_ELEMENTO_WORKFLOW_007.AuditData <= NAT_DASH_AUD_ELEMENTO_WORKFLOW_LOC_008.AuditData
AND ID_007 = ID_ELEMENTO_008
ORDER BY NAT_DASH_AUD_ELEMENTO_WORKFLOW_007."AuditData" DESC
fetch next 1 rows only)
ON ID_007 = ID_ELEMENTO_008
与子查询在选择我被迫选择一列只有
有没有一种SQL标准方法可以做到这一点,而不会因为简单需求而混淆对象或记录?
表格:
CREATE TABLE "NAT_DASH_AUD_ELEMENTO_WORKFLOW_LOC_008"
( "AuditId" NUMBER(9,0),
"AuditAction" VARCHAR2(250 BYTE) ,
"AuditUser" VARCHAR2(250 BYTE) ,
"AuditData" TIMESTAMP (6),
"ID_008" NUMBER(12,0),
"ID_LINGUA_008" NUMBER(9,0),
"ID_ELEMENTO_008" NUMBER(9,0),
"NOTE_008" VARCHAR2(4000 CHAR)
)
和
CREATE TABLE "NAT_DASH_AUD_ELEMENTO_WORKFLOW_007"
( "AuditId" NUMBER(9,0) ,
"AuditAction" VARCHAR2(250 BYTE) ,
"AuditUser" VARCHAR2(250 BYTE),
"AuditData" TIMESTAMP (6),
"ID_007" NUMBER(12,0),
"ID_STATO_ORIGINE_007" NUMBER(9,0),
"ID_STATO_DESTINAZIONE_007" NUMBER(9,0),
"NOTA_OBBLIGATORIA_007" NUMBER(1,0),
"ALLEGATO_OBBLIGATORIO_007" NUMBER(1,0),
"FINALE_007" NUMBER(1,0),
"ID_WORKFLOW_007" NUMBER(9,1)
)
2条答案
按热度按时间wwwo4jvm1#
在Oracle 12中,您可以使用
LATERAL
连接:或者,在早期版本中,使用
ROW_NUMBER
解析函数:kyvafyod2#
你可以检查这个查询: