knex('events').select() .where(knex.raw('events.user_id = users.id')) .sum('upvotes') .as('numupvotes') .count() .as('numevents')