Skip to content
Advertisement

Comparing group-by result with aggregated result

I am trying to retrieve details about stores where their average product prices are higher than the average of all stores in the table.

So far, I have this code:

But this returns the following error:

single-row subquery returns more than one row

In terms of data, I would like to get this result:

where the average prices of those stores are:

and the average price of all stores is 4.6.


Can you help? Thanks in advance.

Advertisement

Answer

You are trying to express:

That is, you want a having clause and don’t need to re-aggregate the data at the StoreId level.

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