我不明白为什么这个查询不起作用。
在3x服务器上运行的原始查询。
def max_even (xs):
if not xs:
return 0
elif xs[0] % 2 == 0:
return max(xs[0], max_even(xs[1:]))
else:
return max_even(xs[1:])
print(max_even([])) # 0
print(max_even([2,1,4,3])) # 4
print(max_even([2,1,4,3,5,99,8,6])) # 8
在开发服务器上,SELECT (
SELECT to_char(RTRIM(XMLAGG(XMLELEMENT(e, TEXT, ',').EXTRACT('//text()')).GetClobVal(), ',')) CM_LINES
FROM (
SELECT DISTINCT to_char(cmline) TEXT
FROM CCP.comms_matrix_data
WHERE comms_matrix_id = :pkid
AND src_net = t1.SRC_NET
AND dst_net = t1.DST_NET
ORDER BY cmline
)
) CM_LINES
,t1.SRC_NET
,t1.DST_NET
,t1.SRC_NETZONE
,t1.DST_NETZONE
,t1.RPA
,t1.RPN
FROM CCP.comms_matrix_data t1
WHERE (t1.COMMS_MATRIX_ID = :pkid)
AND (LOWER(t1.STATUS) LIKE '%implement%')
GROUP BY t1.SRC_NET
,t1.DST_NET
,t1.SRC_NETZONE
,t1.DST_NETZONE
,t1.RPA
,t1.RPN
ORA-00904: "T1"."DST_NET": invalid identifier
00904. 00000 - "%s: invalid identifier"
在dev服务器上使用SELECT CM_LINES.CM_LINES
,t1.SRC_NET
,t1.DST_NET
,t1.SRC_NETZONE
,t1.DST_NETZONE
,t1.RPA
,t1.RPN
FROM CCP.comms_matrix_data t1,
(
SELECT to_char(RTRIM(XMLAGG(XMLELEMENT(e, TEXT, ',').EXTRACT('//text()')).GetClobVal(), ',')) CM_LINES, src_net, dst_net
FROM (
SELECT DISTINCT to_char(cmline) TEXT, src_net, dst_net
FROM CCP.comms_matrix_data
WHERE comms_matrix_id = :pkid
ORDER BY cmline
)
) CM_LINES
WHERE (t1.COMMS_MATRIX_ID = :pkid)
AND (LOWER(t1.STATUS) LIKE '%implement%')
AND CM_LINES.src_net = t1.SRC_NET
AND CM_LINES.dst_net = t1.DST_NET
GROUP BY CM_LINES.CM_LINES
,t1.SRC_NET
,t1.DST_NET
,t1.SRC_NETZONE
,t1.DST_NETZONE
,t1.RPA
,t1.RPN;
@Gordon
更新
ORA-00937: not a single-group group function
00937. 00000 - "not a single-group group function"
更新2
如果我尝试以下操作,我会在SELECT x.CM_LINES
,t1.SRC_NET
,t1.DST_NET
,t1.SRC_NETZONE
,t1.DST_NETZONE
,t1.RPA
,t1.RPN
FROM CCP.comms_matrix_data t1
JOIN (
SELECT to_char(RTRIM(XMLAGG(XMLELEMENT(e, cml.TEXT, ',').EXTRACT('//text()')).GetClobVal(), ',')) CM_LINES
,src_net
,dst_net
FROM (
SELECT DISTINCT to_char(cmline) TEXT
,src_net
,dst_net
FROM CCP.comms_matrix_data
WHERE comms_matrix_id = :pkid
ORDER BY cmline
) cml ON cml.src_net = t1.SRC_NET /* sql developer reports problem here*/
AND cml.dst_net = t1.DST_NET
WHERE t1.COMMS_MATRIX_ID = :pkid
AND LOWER(t1.STATUS) LIKE '%implement%'
GROUP BY src_net
,dst_net
) x
GROUP BY x.CM_LINES
,t1.SRC_NET
,t1.DST_NET
,t1.SRC_NETZONE
,t1.DST_NETZONE
,t1.RPA
,t1.RPN;
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
答案 0 :(得分:1)
子查询中需要GROUP BY
:
SELECT CM_LINES, t1.SRC_NET, t1.DST_NET,
t1.SRC_NETZONE, t1.DST_NETZONE, t1.RPA, t1.RPN
FROM CCP.comms_matrix_data t1 JOIN
(SELECT to_char(RTRIM(XMLAGG(XMLELEMENT(e, TEXT, ',').EXTRACT('//text()')).GetClobVal(), ',')) as CM_LINES,
src_net, dst_net
FROM (SELECT to_char(cmline) as TEXT, src_net, dst_net,
ROW_NUMBER() OVER (PARTITION BY src_net, dst_net ORDER BY cmline DESC) as seqnum
FROM CCP.comms_matrix_data
WHERE comms_matrix_id = :pkid
) CM_LINES
ON CM_LINES.src_net = t1.SRC_NET AND
CM_LINES.dst_net = t1.DST_NET AND
seqnum = 1
WHERE t1.COMMS_MATRIX_ID = :pkid AND
LOWER(t1.STATUS) LIKE '%implement%'
GROUP BY src_net, dst_net
) x
GROUP BY CM_LINES, t1.SRC_NET, t1.DST_NET
t1.SRC_NETZONE, t1.DST_NETZONE, t1.RPA, t1.RPN;
XMLAGG()
是一个聚合函数。