Skip to content
Advertisement

Single-row subquery returns more than one row BUT with one row

“CityJail” schema. I am supposed to find each appeal that has a less than the average number of days between the filing and hearing dates.

Here is my code:

I get an error:

ORA-01427: single-row subquery returns more than one row 01427. 00000 – “single-row subquery returns more than one row” *Cause:
*Action:

Finding the average works fine by itself:

2810.666666666666666666666666666666666667

So I am thinking: it doesn’t like my “GROUP BY” and so I start commenting them out one by one:

And now I am getting the error:

ORA-00920: invalid relational operator 00920. 00000 – “invalid relational operator” *Cause:
*Action: Error at Line: 4 Column: 2

The appeals table:

Advertisement

Answer

I don’t think you need any GROUP BY clause:

The subquery computes the average difference between the two dates over the whole table – don’t use a GROUP BY clause here, otherwise it will return multiple rows, and generate that error. The outer query likely does not need aggregation either.

You could also express this with window functions:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement