sql - MS Access(或 SQL)查询:等效于水平 CountIf()
问题描述
如果我有一组这样的值:
字段 1 | 字段 2 | 字段 3 | 字段 4 |
---|---|---|---|
一个 | 乙 | C | |
2 | 4 | ||
X | 是的 |
如果我想知道每行有多少非空值,在 Excel 中,我可以这样做:
=4 - CountIf(A2:D2, "")
有没有办法在 MS Access(或一般的 SQL)中的查询中做到这一点?
解决方案
您可以将它们添加到 MS Access 中:
select t.*,
(iff(field1 is not null, 1, 0) +
iff(field2 is not null, 1, 0) +
iff(field3 is not null, 1, 0) +
iff(field4 is not null, 1, 0)
) as num_not_null
from t;
推荐阅读
- javascript - 状态改变后 React 渲染相同的谷歌地图
- c# - How To Let A Grid Capture The Mouse, But Still Allow It's Children To Handle Click Events
- javascript - 方法算作函数表达式吗?
- prolog - How not to show if there is same result occurs more than once- Prolog
- java - 在每行包含特定信息的文件中读取有点麻烦
- installation - 运行时的Visual Studio代码“启动json”,如何将调试控制台设置为默认值
- javascript - Unhandled Rejection (TypeError): Cannot read property 'Symbol(Symbol.iterator)' of undefined
- python - How to connect two computers using python
- c# - C# 中的实时数据收集将避免使用互操作进行垃圾收集
- python - multiprocessing.pool.RemoteTraceback,TypeError:不正确的自我类型(必须是“Feature2D”或其派生词)