Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Very simple subqueries
7. Subqueries with functions
Subqueries with multiple results
Correlated subqueries
Other subqueries

Instruction

Nice! Next thing, our subqueries can become more complicated if we include some functions in them. Take a look:

SELECT *
FROM hiking_trip
WHERE length < (
  SELECT AVG(length)
  FROM hiking_trip
);

Now our query looks for all hiking trips with a distance less than the average. As you can see, we used the function AVG() in the subquery which, as you might remember, gives us the average value from a column.

Exercise

Find all information about trips whose price is higher than the average.

Stuck? Here's a hint!

Type:

SELECT *
FROM trip
WHERE price > (
  SELECT AVG(price)
  FROM trip
);