<legend id='FvJXz'><style id='FvJXz'><dir id='FvJXz'><q id='FvJXz'></q></dir></style></legend>
  1. <i id='FvJXz'><tr id='FvJXz'><dt id='FvJXz'><q id='FvJXz'><span id='FvJXz'><b id='FvJXz'><form id='FvJXz'><ins id='FvJXz'></ins><ul id='FvJXz'></ul><sub id='FvJXz'></sub></form><legend id='FvJXz'></legend><bdo id='FvJXz'><pre id='FvJXz'><center id='FvJXz'></center></pre></bdo></b><th id='FvJXz'></th></span></q></dt></tr></i><div id='FvJXz'><tfoot id='FvJXz'></tfoot><dl id='FvJXz'><fieldset id='FvJXz'></fieldset></dl></div>
  2. <tfoot id='FvJXz'></tfoot>
    1. <small id='FvJXz'></small><noframes id='FvJXz'>

        <bdo id='FvJXz'></bdo><ul id='FvJXz'></ul>

      Laravel 不同计数

      时间:2023-09-23
      1. <tfoot id='RXco3'></tfoot>

          <tbody id='RXco3'></tbody>
      2. <legend id='RXco3'><style id='RXco3'><dir id='RXco3'><q id='RXco3'></q></dir></style></legend>

        • <bdo id='RXco3'></bdo><ul id='RXco3'></ul>

          <i id='RXco3'><tr id='RXco3'><dt id='RXco3'><q id='RXco3'><span id='RXco3'><b id='RXco3'><form id='RXco3'><ins id='RXco3'></ins><ul id='RXco3'></ul><sub id='RXco3'></sub></form><legend id='RXco3'></legend><bdo id='RXco3'><pre id='RXco3'><center id='RXco3'></center></pre></bdo></b><th id='RXco3'></th></span></q></dt></tr></i><div id='RXco3'><tfoot id='RXco3'></tfoot><dl id='RXco3'><fieldset id='RXco3'></fieldset></dl></div>
        • <small id='RXco3'></small><noframes id='RXco3'>

                本文介绍了Laravel 不同计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                有什么办法可以让这个查询使用 laravel 工作吗?DB::raw 或 Eloquent 用法无关紧要.

                Any way to make this query work using laravel? DB::raw or Eloquent usage doesn't matter.

                SELECT count(DISTINCT name) FROM tablename;
                

                这是我尝试过但无法获得正确输出的方法:

                Here's what i've tried but cannot get the proper output:

                EloquentTableName::select(DB::raw('count(DISTINCT name) as name_count'))->get();
                

                这会返回类似的内容,我想解决这个问题:

                This returns something like this and i'd like to fix that:

                ([{"name_count":"15"}])
                

                我只想数到 15.

                推荐答案

                你可以这样简单地用 count 替换 get:

                you can simply replace get with count in this way:

                $count = DB::table('tablename')->count(DB::raw('DISTINCT name'));
                

                还可以:

                DB::table('tablename')->distinct('name')->count('name');
                

                这篇关于Laravel 不同计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何将 Laravel Query Builder 结果作为整数获取 下一篇:无法让 Laravel 助理工作

                相关文章

                最新文章

              • <small id='uSy8F'></small><noframes id='uSy8F'>

              • <tfoot id='uSy8F'></tfoot>
                    <bdo id='uSy8F'></bdo><ul id='uSy8F'></ul>
                1. <i id='uSy8F'><tr id='uSy8F'><dt id='uSy8F'><q id='uSy8F'><span id='uSy8F'><b id='uSy8F'><form id='uSy8F'><ins id='uSy8F'></ins><ul id='uSy8F'></ul><sub id='uSy8F'></sub></form><legend id='uSy8F'></legend><bdo id='uSy8F'><pre id='uSy8F'><center id='uSy8F'></center></pre></bdo></b><th id='uSy8F'></th></span></q></dt></tr></i><div id='uSy8F'><tfoot id='uSy8F'></tfoot><dl id='uSy8F'><fieldset id='uSy8F'></fieldset></dl></div>
                    <legend id='uSy8F'><style id='uSy8F'><dir id='uSy8F'><q id='uSy8F'></q></dir></style></legend>