Skip to content
Advertisement

SQL average of a subset of a column

Give the table “shop”

Is there a way to find the list of products(whether A or B) whose price is less or equal to the average price or type A?

I tried the following:

Advertisement

Answer

Use a subquery to find the average price of type A items:

Just for fun, we could also use analytic functions here:

Demo

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