[英]Oracle SQL code syntax standard, Error “not a single-group group function”
I have a block of Oracle SQL code that does work. 我有一块可以正常工作的Oracle SQL代码。 I figured out I cannot get the cert column and the max(run_time) at the same time. 我发现我无法同时获得cert列和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'
);
I was reading a SQL reference and it has the following syntax, but I thought my code matches the syntax? 我正在阅读SQL参考,它具有以下语法,但我认为我的代码符合语法?
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? 有人可以向我解释这个或建议一个说我不能像我那样编写代码的来源吗?
You need a GROUP BY
clause because you have included the cert
column. 您需要GROUP BY
子句,因为您已包含cert
列。 If you had only done SELECT MAX(run_time)
it would not be necessary to supply a GROUP BY
since you are selecting the maximum value of all rows. 如果您只完成了SELECT MAX(run_time)
那么就没有必要提供GROUP BY
因为您选择了所有行的最大值。 But, since you have requested another column ( cert
), Oracle expects that you want to retrieve the max value for each different cert
. 但是,由于您已请求另一个列( cert
),因此Oracle希望您检索每个不同cert
的最大值。
select
cert,
max(run_time)
from
bond_films
where title in ('Casino Royale','On Her Majesty_s Secret Service','Licence to Kill')
GROUP BY cert;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.