php - 如何在laravel中执行平均时忽略空值
问题描述
在 laravel 中执行平均函数时如何忽略 NULL 的值。使用下面的代码,它将空值视为零。对不起我的英语不好希望你明白我的意思谢谢。
下面是我的代码
$average2 =round( $scores->where('student_id',$id)->avg('term2_result'));
解决方案
尝试
$average2 = round($scores->where('student_id', $id)
->where('field_name', '!=', null)
->avg('term2_result'));
推荐阅读
- c - 字节排序 HTTP 客户端
- ruby-on-rails - 我在 Docker 中的何处指定 Postgres 应该运行并接受连接?
- java - MPAndroidChart X 轴显示不正确
- html - 在移动平台上使网站宽度变满
- python - 使用 for 循环打印 python 特定的列表索引
- c - 简单计数器是否需要实现信号量或互斥量?
- excel - VBA如何根据条件跳过行并在满足特定数量的条件时停止
- reactjs - 运行测试时按 id 的元素为 null(无法读取 null 的属性“getAttribute”)
- web3 - `Web3.utils` 未定义,`Web3.eth` 未定义
- html - 如何删除中间的空白
- s,使用 list-group-horizontal (boostrap 4)?