This SQL is working fine:
Just use the working sql.
https://laracasts.com/discuss/channels/laravel/sql-native-to-query-builder
Have you tried to place the join first, I had to reverse one, just example of the join first:
$quy = DB::connection('mysqlv2')->table('dc_powners')
->leftJoin('dc_pets', 'dc_powners.ownerid', '=', 'dc_pets.ownerid')
->select('dc_powners.ownerid', 'dc_powners.oname')->distinct()
->selectRaw('count(dc_pets.petid) as CountOfpetid')
->where('dc_powners.ownerid', '<', 5) // where for testing
->groupby('dc_powners.ownerid')
->orderby('dc_powners.oname')
->get();
Remember these queries can take a little trial and error to figure out.