Home >Backend Development >PHP Tutorial >thinkphp count cannot get the quantity when used in group

thinkphp count cannot get the quantity when used in group

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

<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>

Unable to obtain quantity

<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>

Data can be obtained

Reply content:

<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>

Unable to obtain quantity

<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>

Data can be obtained

Then write it directly as

$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());//Query the total number of records that meet the requirements

The disadvantage is that large data volumes will affect efficiency, resulting in excessive network IO and resource consumption. If it’s a small business, you don’t have to worry too much.

I was just guessing, you try it

<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>

It is best to print out the executed SQL and take a look. For more complex logic, it is best to use native SQL. There is no need to be rigid.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn