Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
COALESCE
使用 COALESCE 将 null 值替换为更有意义的默认值。
用法示例
COALESCE(Field1, Field2, Field3)
语法
COALESCE( field_expression [, field_expression,...])
参数
field_expression - 字段或表达式。所有 field_expressions 都必须是同一类型。
示例
假设您要跟踪比赛中多个赛车手的多次预赛成绩。赛车手可能会因各种原因而缺席预赛。您希望创建一个 First_Time 字段,其中包含每位赛车手的首次比赛结果。
以下为比赛数据。
| Racer |
Heat1 |
Heat2 |
Heat3 |
| Racer X |
|
38.22 |
37.61 |
| Racer Y |
41.33 |
|
38.04 |
| Racer Z |
39.27 |
39.04 |
38.85 |
在 First_Time 字段中使用以下公式,从 Heat 列中获取第一个非 null 值:
COALESCE(Heat1, Heat2, Heat3)
结果:
| Racer |
Heat1 |
Heat2 |
Heat3 |
First_Time |
| Racer X |
null |
38.22 |
37.61 |
38.22 |
| Racer Y |
41.33 |
null |
38.04 |
41.33 |
| Racer Z |
39.27 |
39.04 |
38.85 |
39.27 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-05-28。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2026-05-28。"],[],[]]