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
Release: 2016-07-06 13:52:30
Original
1791 people have browsed it

<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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template