开发者

Oracle SQL code syntax standard, Error "not a single-group group function"

开发者 https://www.devze.com 2023-03-31 14:17 出处:网络
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.

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 expl开发者_高级运维ain 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. 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;
0

精彩评论

暂无评论...
验证码 换一张
取 消