SELECT *
FROM Movies
WHERE (SELECT AVG(Score)
FROM Reviews WHERE MovieId=Id)>2
Is it even possible to write subqueries in laravel query builder?
CodePudding user response:
Try this:
DB::table('movies')
->join('reviews', 'reviews.movieId', '=', 'movies.id)
->select(DB::raw('avg(reviews.score) as score'))
->where([
['reviews.movieId', '>', 2],
// [ if any other clause]
])
->get();