Heim >Backend-Entwicklung >PHP-Tutorial >thinkphp count用于group就无法获取数量

thinkphp count用于group就无法获取数量

WBOY
WBOYOriginal
2016-07-06 13:52:301790Durchsuche

<code>  $count = $order->where($con)
            ->join("LEFT JOIN x_goods ON x_goods.goods_id = x_order.order_goodsid")
            ->order("order_createtime desc")
            ->group("order_no")
            ->count();// 查询满足要求的总记录数</code>

无法获取数量

<code>  $count = $order->where($con)
            ->join("LEFT JOIN x_goods ON x_goods.goods_id = x_order.order_goodsid")
            ->order("order_createtime desc")
            ->group("order_no")
            ->select();// 查询满足要求的总记录数</code>

可以获取数据

回复内容:

<code>  $count = $order->where($con)
            ->join("LEFT JOIN x_goods ON x_goods.goods_id = x_order.order_goodsid")
            ->order("order_createtime desc")
            ->group("order_no")
            ->count();// 查询满足要求的总记录数</code>

无法获取数量

<code>  $count = $order->where($con)
            ->join("LEFT JOIN x_goods ON x_goods.goods_id = x_order.order_goodsid")
            ->order("order_createtime desc")
            ->group("order_no")
            ->select();// 查询满足要求的总记录数</code>

可以获取数据

那就直接写成

$count = count($order->where($con) ->join("LEFT JOIN x_goods ON x_goods.goods_id = x_order.order_goodsid") ->order("order_createtime desc") ->group("order_no") ->select());// 查询满足要求的总记录数

缺陷是大数据量下会影响效率,导致网络io和资源消耗过大。小业务的话就不必多虑。

我瞎猜的哈,你试试

<code class="php">$count = $order->where($con)
            ->join("LEFT JOIN x_goods ON x_goods.goods_id = x_order.order_goodsid")
            ->order("order_createtime desc")
            ->group("order_no")
            ->field("count(*)")
            ->select();//</code>

最好把执行的SQL打印出来看下,比较复杂的逻辑用原生SQL最好,没必要拘泥。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn