本文介绍了当它为NULL时,如何用MAX函数设置0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解如何使用MAX函数将属性的0值设置为NULL.例如:

I would like to understand how to set 0 value of the attribute when it is NULL with MAX function. For example:

Name columns:
number - date

Values:
10 - 2012-04-04
11 - 2012-04-04
12 - 2012-04-04
13 - 2012-04-15
14 - 2012-06-21
 1 - 2013-07-04

数字是增量字段,但是当新年到来时,它已将自己设置为1.但是结果:

Number is incremental field, but it has set itself 1 when new year has come.But result of:

SELECT (MAX(number)+1) number WHERE date LIKE "2014%"

为NULL而不是1,因为MAX(number)为NULL而不是0

is NULL and not 1 because MAX(number) is NULL and not 0

推荐答案

好吧,因为没有像2014年这样的日期,所以您会期望为null,因为最大的东西实际上并没有.

Well, as there is no date like 2014, you would expect null, because the maximum of nothing is actually not anyting.

但是要这样做:

COALESCE(MAX(number),0)

这意味着:从下一个列表中获取第一个非空值,因此,如果您的max为空,它将为您提供0

Which means: get the first non-null thing from the next list, so if your max is null, it'll give you 0

这篇关于当它为NULL时,如何用MAX函数设置0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:36