sqlite - 有没有办法让 max 函数忽略 sqlite 列中的空值?
问题描述
简而言之,如果我有一个包含两列(例如人员和高度)的表格,我可以使用 select max(height) from 'table' group by people,它将为任何一组人员生成最大高度_忽略任何空值_。
但是,如果我有一个包含更多列(height_1、height_2、height_3 等)的表,并且我想用一个显示最大高度(height_1、height_2、height_3、max_height)的新列来简单地重现该表,我会直观地喜欢放。
select
height_1,
height_2,
height_3,
max(height_1, height_2, height_3) as max_height
from 'table'
但是以这种方式使用,max 似乎表现不同,如果任何参数为 null,则返回 null。
是否有某种形式的使用可以让它在聚合列时表现得像它一样,并忽略空值?即使在一系列列中聚合单个值?
解决方案
你可以使用类似的东西:
SELECT height_1
, height_2
, height_3
, max(ifnull(height_1, 0), ifnull(height_2, 0), ifnull(height_3, 0)) AS max_height
FROM "table"
推荐阅读
- python - 当我从 Muse 监视器应用程序接收到 EEG 数据时,这些值是乱码,我如何将它们转换为在线分析?
- angular - TypeError:“'caller'、'callee' 和 'arguments' 属性可能无法在严格模式函数或调用它们的参数对象上访问”
- python-3.x - Python3 TypeError:字符串索引必须是整数
- azure - Azure Policy 中 match 和 like 通配符之间的区别
- python - 如何使用 pandas 创建索引循环 FIFO 缓冲区
- python - 索引包含重复条目,无法重塑
- javascript - JavaScript 中的 DOM 操作和警报函数行为
- python - 并行使用 StanfordCoreNLP
- python-3.x - 在非阻塞套接字上接收数据时如何修复阻塞错误
- json - 使用 HDFS 接收器连接器配置问题的 Kafka 主题数据到 HDFS parquet 文件