SQL显式语法子查询连接

时间:2015-09-07 00:36:26

标签: sql oracle join

我正在尝试从子查询加入到main中的多个字段,并且想要知道如何编写连接,以避免在子查询中重新定义主表。

我需要限制子查询的结果,如果它是持有者或条件(aXM.ATTRIB_03),这就是我试图通过子查询加入的原因。计划是根据条件子中返回的内容聚合条件,参见建议的输出。

虽然代码片段中没有显示,但在每个子查询中返回多个结果也很重要。

我一直在尝试使用以下查询,这个问题是子查询不知道别名“Ass

  

(ORA-00904:“ASS”。“ROW_ID”:标识符无效)

SELECT 
  Ass.NAME AS REGISTER_NAME,
  Ass.ASSET_NUM AS SMSF_NUM,
  HOLDER.SMSF_HOLDER_TYPE,
  CONDITION.xCONDITION

FROM
  siebel.s_asset Ass

  LEFT JOIN
  (
    SELECT aXM.par_row_id AS hCon, aXM.ATTRIB_44 AS SMSF_HOLDER_TYPE
    FROM Siebel.S_ASSET_XM aXM
    WHERE Ass.row_id = aXM.par_row_id
      AND aXM.ATTRIB_03 IS NULL
  ) HOLDER
  ON Ass.row_id = HOLDER.hCon

  LEFT JOIN
  (
    SELECT aXM.par_row_id AS cCon, aXM.ATTRIB_44 AS xCONDITION
    FROM Siebel.S_ASSET_XM aXM
    WHERE Ass.row_id = aXM.par_row_id
      AND aXM.ATTRIB_03 = 'Condition'
  ) CONDITION
  ON Ass.row_id = CONDITION.cCon

WHERE
  AND Ass.NAME = 'SMSF Auditor'
  AND Ass.STATUS_CD = 'Registered'

期望输出

REGISTER_NAME   SMSF_NUM    SMSF_HOLDER_TYPE        SMSF_CONDITION
SMSF Auditor    100259612   Individual Auditor      Condition 1~ Condition 2~ Condition 3
SMSF Auditor    100259747   Individual Auditor      Condition 1~ Condition 2~ Condition 3
SMSF Auditor    100259907   Individual Auditor      Condition 1~ Condition 2~ Condition 3

2 个答案:

答案 0 :(得分:0)

您无法在内部查询中使用$("#canvas").click(function(e){ var cRect = canvas.getBoundingClientRect(); var mouseX = e.clientX - cRect.left; var mouseY = e.clientY - cRect.top; var figureX = posicion; var figureY = 0; var figureW_off = posicion + tamano; var figureH_off = 400-tamano; ctx.fillStyle = color[Math.floor(Math.random() * 4)]; if(mouseX >= figureX && mouseX <= figureW_off && mouseY >= figureY && mouseY <= figureH_off) { $("p").text( "The Width of the figure is " + tamano+ " and the Height is " + (400-tamano)); } }); 别名。

试试这个。看起来也是这样。

ASS

答案 1 :(得分:0)

您可以像这样重写您的查询

  SELECT 
  Ass.NAME AS REGISTER_NAME,
  Ass.ASSET_NUM AS SMSF_NUM,
  HOLDER.SMSF_HOLDER_TYPE

FROM
  siebel.s_asset Ass
  left join Siebel.S_ASSET_XM HOLDER on Ass.Ass.row_id = HOLDER.par_row_id
  inner join Siebel.S_ASSET_XM aXM ON Ass.row_id = aXM.par_row_id