groupby用于对数据集合进行分组,例如:

//查询订单表中每个用户的订单总额
Db('order')->select([
            'field' => ['SUM(OrderPrice) as Price','userId'],
            'groupby' => 'userId'
        ])->get();
//sql:SELECT SUM(OrderPrice) as Price,`userId` FROM `order` GROUP BY userId;

SQL小技巧:对于查询频率高的多数据表,建立字段索引将大大提高查询速度