我认为错误描述有点误导,因为我没有看到查询结束的方式有任何问题。我试图加入三个表,这是行不通的。有人能指出我做错了吗?顺便说一句,这是在Oracle上。
SELECT s.PITIMEDATE, ROUND(SYSDATE-s.PITIMEDATE) DIFFDAYS, s.SRC, s.VSA6, a.VSA9, c.COMMENTS, c.Actions, c.MYID
FROM alarm_standing_MAU AS s
INNER JOIN alarm_MAU AS a
ON a.SRC = s.SRC
AND a.VSA9 =
(SELECT VSA9
FROM a
WHERE a.SRC = s.SRC
AND ROWNUM=1)
INNER JOIN Alarm_Standing_Comments AS c
ON c.SRC = s.SRC
AND s.SRC<>'LastCheck'
GROUP BY s.SRC, s.PITIMEDATE, s.VSA6, a.VSA9, c.Comments, c.Actions, c.MYID
ORDER BY s.PITIMEDATE ASC
有关更多信息,我试图在查询中添加第二个连接,但它有点笨拙,所以正在尝试使用别名。这是最初的查询 - 我有兴趣知道如何通过别名提高可读性。
SELECT alarm_standing_MAU.PITIMEDATE, ROUND(SYSDATE-alarm_standing_MAU.PITIMEDATE) DIFFDAYS, alarm_standing_MAU.SRC, alarm_standing_MAU.VSA6, alarm_MAU.VSA9
FROM alarm_standing_MAU
INNER JOIN alarm_MAU
ON alarm_MAU.SRC = alarm_standing_MAU.SRC
AND alarm_MAU.VSA9 =
(SELECT VSA9
FROM alarm_MAU
WHERE alarm_MAU.SRC = alarm_standing_MAU.SRC
AND ROWNUM=1)
AND alarm_standing_MAU.SRC<>'LastCheck'
GROUP BY alarm_standing_MAU.SRC, alarm_standing_MAU.PITIMEDATE, alarm_standing_MAU.VSA6, alarm_MAU.VSA9
ORDER BY alarm_standing_MAU.PITIMEDATE ASC
答案 0 :(得分:0)
作为提示,您不能在from子句中使用别名:
INNER JOIN alarm_MAU AS a
ON a.SRC = s.SRC
AND a.VSA9 =
(SELECT VSA9
FROM a <-- Oops. Might try "FROM alarm_MAU as b" ?
WHERE a.SRC = s.SRC
AND ROWNUM=1)
我不确定你要完成什么,但这就是我要开始的地方。
答案 1 :(得分:0)
如果子查询使用与主查询相同的表,那么您可以在主查询中使用a1,在子查询中使用a2,例如
。SELECT s.PITIMEDATE,
ROUND(SYSDATE-s.PITIMEDATE) DIFFDAYS,
s.SRC,
s.VSA6,
a1.VSA9
FROM alarm_standing_MAU s
INNER JOIN alarm_MAU a1
ON a1.SRC = s.SRC
AND a1.VSA9 =
(SELECT a2.VSA9
FROM alarm_MAU a2
WHERE a2.SRC = s.SRC
AND ROWNUM=1)
AND s.SRC<>'LastCheck'
GROUP BY s.SRC,
s.PITIMEDATE,
s.VSA6,
a1.VSA9
ORDER BY s.PITIMEDATE ASC