很确定这一定与最大值有关,但不确定如何解决问题。。。。选择失败。3504:(-3504)选定的非聚合值必须是关联组的一部分。任何反馈/建议/帮助都将不胜感激。试图收集大量设备(30k+)的各种维护计划的最后完成日期。我很难找到适合自己的问题。
SELECT
MRC,
EQUIPMENT,
DESCRIPTION,
CLASSCODE,
CRITICALITY,
STATUS,
PM,
PMDESCRIPTION,
NEXTDUE,
PMTYPE,
ASSIGNEDBY,
ASSIGNEDTO,
FREQUENCY,
UOM,
WOEQUIP,
WORKORDER,
WORKORDERPM,
CHECKS,
MAX(LastCompleted) AS CDATE,
WOSTATUS
FROM
(SELECT
SE.EquipmentSurfaceAssetBK AS "MRC",
SE.EquipmentCodeBK AS "EQUIPMENT",
SE.EquipmentDescription AS "DESCRIPTION",
SE.EquipmentClassBK AS "CLASSCODE",
SE.EquipmentCriticality AS "CRITICALITY",
SE.EquipmentCostCode AS "COSTCODE",
SE.EquipmentStatus AS "STATUS",
PE.EqPMCodeBK AS "PM",
PM.PMDescription AS "PMDESCRIPTION",
PE.EqPMDueDate AS "NEXTDUE",
PE.EqPMType AS "PMTYPE",
PE.EqPMDeactivatedDate AS "DDATE",
PE.EqPMAssignedBy AS "ASSIGNEDBY",
PE.EqPMAssignedToResourceBK AS "ASSIGNEDTO",
PE.EqPMFrequency AS "FREQUENCY",
PE.EqPMFrequencyUOM AS "UOM",
WO.WorkOrderEquipmentcodeBK AS "WOEQUIP",
WO.WorkOrderCodeBK AS "WORKORDER",
WO.WorkOrderPMCodeBK AS "WORKORDERPM",
CASE
WHEN WO.WorkOrderPMCodeBK = PE.EqPMCodeBK THEN 'YES' ELSE 'NO'
END AS "CHECKS",
WO.WorkOrderStatus AS "WOSTATUS",
WO.WorkOrderCompletedDate AS "LastCompleted"
FROM IDW_PL_SURFACE.DIMSurfaceEquipment SE
JOIN IDW_PL_SURFACE.DIMEquipmentPM PE ON SE.EquipmentCodeBK = PE.EqPMEquipmentCodeBK
JOIN IDW_PL_SURFACE.DIMSurfacePM PM ON PE.EqPMCodeBK = PM.PMCodeBK
JOIN IDW_PL_SURFACE.DIMWorkOrder WO ON SE.EquipmentCodeBK = WO.WorkOrderEquipmentcodeBK) AS ST
WHERE
1=1
AND
STATUS IN ( 'I', 'IDLE')
AND
DDATE is Null
AND
PMTYPE IN ( 'V', 'F')
AND "CHECKS" IN ( 'YES')
GROUP BY
EQUIPMENT
2条答案
按热度按时间xqkwcwgp1#
如果你只想要最新的那一排
LastCompleted
每EQUIPMENT
应用等级/行号:p3rjfoxz2#
“select”中的非聚合列与“groupby”中列出的列不匹配。您可以将select中的所有内容(lastcompleted除外)添加到group by,也可以从select中删除一组列: