Correlated SQL
query:
SELECT restaurantid FROM restaurants WHERE annualsales < (
SELECT AVG(annualsales) FROM restaurants GROUP BY typeofservice
)
explanation :
- In correlated queries inner query executes once per each row of
the outer query.
- In internal query restaurants are grouped by type of service .
Average of the annualsales is calculated of all the restaurants
from this group .
- For each value of annualsales from outer query checks with the
output of inner query i.e., whether the annual sales of restaurant
is less than average sale or not.