【发布时间】:2016-06-22 04:50:14
【问题描述】:
我的代码
DB::table('users_tb')->leftjoin('device_tb', 'device_tb.user_id', '=', 'users_tb.user_id')
->leftjoin('part_tb', 'device_tb.device_id', '=', 'part_tb.device_id')
->select('users_tb.user_name', DB::raw("(SELECT COUNT(part_tb.id) FROM part_tb) AS counter"))
->where('users_tb.level', '>', 7)
->havingRaw("(SELECT COUNT(part_tb.id) FROM part_tb) > 0")
->groupBy('device_tb.device_id')
->orderBy('users_tb.user_name')
->get()->toArray();
我的结果:
Name1 - 3
Name1 - 4
Name1 - 3
Name2 - 11
Name2 - 2
我怎样才能 SUM 计数器? (使用查询生成器/SQL 查询)示例:
Name1 - 10 (3+4+3)
Name2 - 13 (11 + 2)
请有人帮帮我!!
【问题讨论】:
标签: php laravel laravel-5.1