It looks like you're new here. If you want to get involved, click one of these buttons!
I would like to fetch the sum (or avg) of a column.
Is it possible?
Also I'm interested in adding subqueries but I have not been able to find examples in the documentation.
You can fetch a sum or avg like this:
$res = User::query ('sum(id) as count, avg(id) as average')->fetch_orig ();
The query builder doesn't do subqueries aside from many-many relations. I usually write subqueries and complex joins manually through DB::fetch() so I have more control and can test for optimal performance.