最大非空列 [英] Greatest not null column

查看:57
本文介绍了最大非空列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用基于两个DATETIME列的最大值的公式更新一行.我通常会这样做:

I need to update a row with a formula based on the largest value of two DATETIME columns. I would normally do this:

GREATEST(date_one, date_two)

但是,两个列都可以为NULL.即使另一个为NULL,我也需要最大的日期(当然,当两个均为NULL时,我希望为NULL),并且当其中一列为NULL时GREATEST()返回NULL.

However, both columns are allowed to be NULL. I need the greatest date even when the other is NULL (of course, I expect NULL when both are NULL) and GREATEST() returns NULL when one of the columns is NULL.

这似乎可行:

GREATEST(COALESCE(date_one, date_two), COALESCE(date_two, date_one))

但是我不知道...我想念一个更简单的方法吗?

But I wonder... am I missing a more straightforward method?

推荐答案

COALESCE(GREATEST(date_one, date_two), date_one, date_two)

这篇关于最大非空列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆