如何在Query builder Laravel5.6中使用count

时间:2018-04-16 16:34:39

标签: laravel count

这是我的查询构建器。但是显示错误

  

错误=> count():参数必须是数组或实现的对象   可列

{{ user.last_login }}

任何人都可以找出我的问题吗?

1 个答案:

答案 0 :(得分:0)

使用LongStream a = LongStream.iterate(286, i->i+1).map(i -> Math.multiplyExact(i, i+1)/2); LongStream b = LongStream.iterate(166, i->i+1).map(i -> Math.multiplyExact(i, 3*i-1)/2); LongStream c = LongStream.iterate(144, i->i+1).map(i -> Math.multiplyExact(i, 2*i-1)); OfLong aIter = a.iterator(); OfLong bIter = b.iterator(); OfLong cIter = c.iterator(); long aVal = aIter.nextLong(); long bVal = bIter.nextLong(); long cVal = cIter.nextLong(); while (aVal != bVal || bVal != cVal) { long min = Math.min(Math.min(aVal, bVal), cVal); if (aVal == min) aVal = aIter.nextLong(); if (bVal == min) bVal = bIter.nextLong(); if (cVal == min) cVal = cIter.nextLong(); } System.out.println(aVal);

DB::raw("count(pams_project.dev_id) as count")

但请务必使用$project = DB::table('pams_project') ->join('pams_developer', 'pams_project.dev_id', '=', 'pams_developer.id') ->select(array('pams_developer.developer_name',DB::raw("count(pams_project.dev_id) as count"))) ->get();

如果你想获得收集的数量,你可以简单地使用GroupBy()

希望这有帮助