laravel中的计数功能机制

时间:2019-05-25 09:19:25

标签: php mysql laravel eloquent

假设我们有此代码

count()函数的结果是关于每个查询或查询之后的 执行然后计数函数返回结果?

select distinct this.dtncode as y0, this.dtname11 as y1 
from village_master this
order by this.dtname11 asc

2 个答案:

答案 0 :(得分:0)

$model=Model::query()

    foreach ($Entities as $entity) {
        $model->orWhereBetween("id",$entity->first_id,$entity->last_id])
    }

//$model - object of query builder
$model->count();

它将生成一个查询并在数据库端进行计算:SELECT COUNT(*) FROM table WHERE id BETWEEN ? AND ? OR id BETWEEN ? AND ? OR id BETWEEN ? AND ?

答案 1 :(得分:0)

萨拉姆,
答案:这取决于您何时调用计数方法!
在您的代码中:

alter table EBSIEMSTransfernew
    add batchnumber = datediff(day, '2019-05-04', invoice_date);

希望对您有所帮助:)