美文网首页
thinkphp5 sum聚合函数使用方法 sum使用where

thinkphp5 sum聚合函数使用方法 sum使用where

作者: 思议岁月 | 来源:发表于2019-05-27 22:48 被阅读0次

今天在做tp5项目的时候,使用sum聚合函数统计结果值一直为null,着落半天解决不了,最后找到原因,在此记录下。
项目是统计昨天的某字段和。
以下为原来代码

$yestoday=date('Y-m-d',strtotime('-1 day'));
$yuedu=Db::table('cs_fanwen')->where(['beifanwen_id'=>55,'time'=>$yestoday] )->sum('istixin');

原因是在时间比较的时候不能使用where,解决办法

$yestoday=date('Y-m-d',strtotime('-1 day'));
 $yuedu=Db::table('cs_fanwen')->where('beifanwen_id',55)->whereTime('time',$yestoday)->sum('istixin');

注意时间筛选使用whereTime
注意补充:经过自己筛选的知,当没有记录时访问结果为null,与上面无关。

相关文章

网友评论

      本文标题:thinkphp5 sum聚合函数使用方法 sum使用where

      本文链接:https://www.haomeiwen.com/subject/utcltctx.html