gpt4 book ai didi

sql - ORACLE SQL 中的 MAX()

转载 作者:行者123 更新时间:2023-12-04 23:16:52 24 4
gpt4 key购买 nike

我有一个表,其中存储了已完成维护任务的记录列表以及完成的日期和时间。我正在尝试执行子查询以提取具有最新日期的每个任务的记录。我的 SQL 语句是:

    SELECT "ENGINEERING_COMPLIANCE"."EO" AS "EO",
"ENGINEERING_COMPLIANCE"."AC" AS "AC",
"ENGINEERING_COMPLIANCE"."PN" AS "PN",
"ENGINEERING_COMPLIANCE"."PN_SN" AS "PN_SN",
"ENGINEERING_COMPLIANCE"."HOURS_RESET" AS "HOURS_RESET",
"ENGINEERING_COMPLIANCE"."MINUTES_RESET" AS "MINUTES_RESET",
"ENGINEERING_COMPLIANCE"."CYCLES_RESET" AS "CYCLES_RESET",
"ENGINEERING_COMPLIANCE"."RESET_DATE" AS "RESET_DATE",
"ENGINEERING_COMPLIANCE"."RESET_HOUR" AS "RESET_HOUR",
"ENGINEERING_COMPLIANCE"."RESET_MINUTE" AS "RESET_MINUTE",
MAX ( "ENGINEERING_COMPLIANCE"."RESET_DATE" ) AS "LAST_COMP_DATE"
FROM ENGINEERING_COMPLIANCE
GROUP BY ( "ENGINEERING_COMPLIANCE"."EO" ) ,
( "ENGINEERING_COMPLIANCE"."AC" ) ,
( "ENGINEERING_COMPLIANCE"."PN" ) ,
( "ENGINEERING_COMPLIANCE"."PN_SN" )

但是我不断收到以下错误:“ORA-00979:不是 GROUP BY 表达式”

当我删除“GROUP BY”时,我得到:
“ORA-00937:不是单组组函数”

1 - 这到底是什么意思
2 - 声明有什么问题?

最佳答案

我根本不了解 MySQL,但是,在 Oracle 中,您需要按选择列表中列出的所有非聚合功能列进行分组。

这样的事情应该工作:

 SELECT "engineering_compliance"."eo"               AS "EO", 
"engineering_compliance"."ac" AS "AC",
"engineering_compliance"."pn" AS "PN",
"engineering_compliance"."pn_sn" AS "PN_SN",
"engineering_compliance"."hours_reset" AS "HOURS_RESET",
"engineering_compliance"."minutes_reset" AS "MINUTES_RESET",
"engineering_compliance"."cycles_reset" AS "CYCLES_RESET",
"engineering_compliance"."reset_date" AS "RESET_DATE",
"engineering_compliance"."reset_hour" AS "RESET_HOUR",
"engineering_compliance"."reset_minute" AS "RESET_MINUTE",
Max ("engineering_compliance"."reset_date") AS "LAST_COMP_DATE"
FROM engineering_compliance
GROUP BY "engineering_compliance"."eo",
"engineering_compliance"."ac",
"engineering_compliance"."pn",
"engineering_compliance"."pn_sn",
"engineering_compliance"."hours_reset",
"engineering_compliance"."minutes_reset",
"engineering_compliance"."cycles_reset",
"engineering_compliance"."reset_date",
"engineering_compliance"."reset_hour",
"engineering_compliance"."reset_minute";

关于sql - ORACLE SQL 中的 MAX(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38404982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com