Oracle SQL代码语法标准,错误“不是单组组函数”
我有一段可以运行的 Oracle SQL 代码。我发现我无法同时获取证书列和 max(run_time) 。
select
cert,
max(run_time)
from
bond_films
where title in
(
'Casino Royale','On Her Majesty_s Secret Service','Licence to Kill'
);
我正在阅读 SQL 参考,它具有以下语法,但我认为我的代码与语法匹配?
SELECT [column,] group_function(column)
FROM table
[WHERE condition]
[GROUP BY group_by_expression]
[HAVING group_condition]
[ORDER BY column] ;
有人可以向我解释一下这一点,或者建议一个消息来源说我不能像我一样编写代码吗?
I have a block of Oracle SQL code that does work. I figured out I cannot get the cert column and the max(run_time) at the same time.
select
cert,
max(run_time)
from
bond_films
where title in
(
'Casino Royale','On Her Majesty_s Secret Service','Licence to Kill'
);
I was reading a SQL reference and it has the following syntax, but I thought my code matches the syntax?
SELECT [column,] group_function(column)
FROM table
[WHERE condition]
[GROUP BY group_by_expression]
[HAVING group_condition]
[ORDER BY column] ;
Can someone explain this to me or suggest a source which says I cannot write a code like I did?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个
GROUP BY
子句,因为您已包含cert
列。如果您只执行了SELECT MAX(run_time)
,则无需提供GROUP BY
,因为您选择的是所有行的最大值。但是,由于您请求了另一列 (cert
),Oracle 希望您希望检索每个不同cert
的最大值。You need a
GROUP BY
clause because you have included thecert
column. If you had only doneSELECT MAX(run_time)
it would not be necessary to supply aGROUP BY
since you are selecting the maximum value of all rows. But, since you have requested another column (cert
), Oracle expects that you want to retrieve the max value for each differentcert
.