我有一个输出的Oracle查询
但是我希望输出除事件ID(即
)以外的所有不同的列我尝试将GROUP BY添加到Oracle Query,但出现错误,
DataSource.Error: Oracle: ORA-00979: not a GROUP BY expression
Details:
DataSourceKind=Oracle
DataSourcePath=dlporacle
Message=ORA-00979: not a GROUP BY expression
ErrorCode=-2147467259
以下是我的查询...请协助
SELECT
I.INCIDENTID AS "Incident ID",
I.CREATIONDATE AS "Creation Date",
MO.IPADDRESS AS "IP Address",
MO.DOMAINUSERNAME AS "Login ID",
MO.ENDPOINTMACHINENAME AS "Computer Name",
M.MESSAGESUBJECT AS "Email Subject"
FROM MESSAGE M,
JOIN INCIDENT I ON M.MESSAGEID = I.MESSAGEID AND M.MESSAGESOURCE = I.MESSAGESOURCE AND M.MESSAGEDATE = I.MESSAGEDATE
JOIN MESSAGEORIGINATOR MO ON M.MESSAGEORIGINATORID = MO.MESSAGEORIGINATORID
WHERE M.MESSAGESOURCE = 'ENDPOINT'
AND I.ISDELETED = 0
GROUP BY MO.IPADDRESS, MO.DOMAINUSERNAME, MO.ENDPOINTMACHINENAME, M.MESSAGESUBJECT
答案 0 :(得分:1)
尝试一下
SELECT MIN(I.INCIDENTID) AS "Incident ID",
I.CREATIONDATE AS "Creation Date",
MO.IPADDRESS AS "IP Address",
MO.DOMAINUSERNAME AS "Login ID",
MO.ENDPOINTMACHINENAME AS "Computer Name",
M.MESSAGESUBJECT AS "Email Subject"
FROM MESSAGE M,
INCIDENT I,
MESSAGEORIGINATOR MO
WHERE M.MESSAGESOURCE = 'ENDPOINT'
AND M.MESSAGESOURCE = I.MESSAGESOURCE
AND M.MESSAGEID = I.MESSAGEID
AND M.MESSAGEDATE = I.MESSAGEDATE
AND M.MESSAGEORIGINATORID = MO.MESSAGEORIGINATORID
AND I.ISDELETED = 0
GROUP BY I.CREATIONDATE, MO.IPADDRESS, MO.DOMAINUSERNAME, MO.ENDPOINTMACHINENAME,M.MESSAGESUBJECT
答案 1 :(得分:1)
修复JOIN
语法并使用聚合:
SELECT
MIN(I.INCIDENTID) AS "Incident ID",
I.CREATIONDATE AS "Creation Date",
MO.IPADDRESS AS "IP Address",
MO.DOMAINUSERNAME AS "Login ID",
MO.ENDPOINTMACHINENAME AS "Computer Name",
M.MESSAGESUBJECT AS "Email Subject"
FROM MESSAGE M JOIN
INCIDENT I
ON M.MESSAGEID = I.MESSAGEID AND
M.MESSAGESOURCE = I.MESSAGESOURCE AND
M.MESSAGEDATE = I.MESSAGEDATE JOIN
MESSAGEORIGINATOR MO
ON M.MESSAGEORIGINATORID = MO.MESSAGEORIGINATORID
WHERE M.MESSAGESOURCE = 'ENDPOINT' AND I.ISDELETED = 0
GROUP BY I.CREATIONDATE, MO.IPADDRESS, MO.DOMAINUSERNAME, MO.ENDPOINTMACHINENAME, M.MESSAGESUBJECT
所有未聚合的列必须位于GROUP BY
中。
为什么加入INCIDENT
的消息的来源和日期以及消息ID必须匹配?看来消息ID应该足够。