سؤال

I keep getting an error when I am trying to execute this code on Oracle

SELECT id,
       Max(id),
       artist AS"Artist"
FROM   d_songs
WHERE  duration IN( '3 min', '6 min', '10 min' )
HAVING id < 50
GROUP  BY id; 

What am I doing wrong? It is saying that this is not a group by expression.

هل كانت مفيدة؟

المحلول

Edit:

After you're edit, see this from the documentation:

You attempted to execute a SELECT statement which contained a GROUP BY function such as MIN, MAX, SUM or COUNT. You attempted to execute an expression within the SELECT list which is not in the GROUP BY clause.

Put Group By before Having, and also include all fields (not the max) in the Group By Clause

SELECT id, max(id), artist as "Artist"
From d_songs
Where duration in('3 min', '6 min', '10 min')
where id < 50
Group by id, artist

You can view the docs for more information

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top