Oracle SQL代码语法标准,错误“不是单组组函数”

发布于 2024-12-02 14:56:48 字数 486 浏览 0 评论 0原文

我有一段可以运行的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贩梦商人 2024-12-09 14:56:48

您需要一个 GROUP BY 子句,因为您已包含 cert 列。如果您只执行了SELECT MAX(run_time),则无需提供GROUP BY,因为您选择的是所有行的最大值。但是,由于您请求了另一列 (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;

You need a GROUP BY clause because you have included the cert column. 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. But, since you have requested another column (cert), Oracle expects that you want to retrieve the max value for each different 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文