所以这里我有数据库的结构:
情况如下,假设我有一个 ID 为 1294652442332 的子元素“Sivu”和几个属性(不重要)。我需要选择我的 Sivu 的父页面(页面是 Sivu 的父元素)。当前工作的 oracle DB 查询是
SELECT
DISTINCT parent.oid as parentid
, parent.otype as parenttype
, child.oid as childid
, child.otype as childtype
, child.ncode as ncode
, child.nrank as nrank
FROM
assetrelationtree child
, assetrelationtree parent
, Page parentasset
WHERE
child.oid = 1294652442332
AND child.otype = 'Sivu'
AND child.nparentid != 0
AND child.ncode = '-'
AND parent.nid = child.nparentid
AND parent.otype = 'Page'
AND parentasset.id = parent.oid
AND parentasset.status != 'VO'
ORDER BY
nrank
现在,在图片中您会看到有一个siteplan 表(OID 字段包含Page ID)。它还包含关于 Page(Sivu 的父元素)的另一件重要的事情。我想知道的重要领域是NCODE。因此,基本上,我想修改此查询以选择在表 siteplantree 中具有 NCODE 字段的页面元素具有特定值(NCODE = 'Placed')。我试图修改查询,但我被卡住了,我什至不知道单次选择是否可行:
SELECT
DISTINCT parent.oid as parentid
, parent.otype as parenttype
, child.oid as childid
, child.otype as childtype
, child.ncode as ncode
, child.nrank as nrank
FROM
assetrelationtree child
, assetrelationtree parent
, Page parentasset
, siteplantree siteplan
WHERE
child.oid = 1294652442332
AND child.otype = 'Sivu'
AND child.nparentid != 0
AND child.ncode = '-'
AND parent.nid = child.nparentid
AND parent.otype = 'Page'
AND parentasset.id = parent.oid
AND parentasset.status != 'VO'
AND siteplan.ncode = 'Placed'
AND siteplan.oid = child.nparentid
ORDER BY
nrank
希望我已经描述了问题,以便您能够理解。如果有些事情不清楚,请告诉我,我会更新描述。