Treat Null value in Max function
Hi all,
I need to find out the max. value of a column. But if there is a null in this column, I need to return null.
For example, the table Table_1 has column Col_1 with following rows:
1, 2, null.
If I issue SQL:
select max(col_1) from table_1,
Oracle will return 2.
But I want to return null.
Is it any way to do it?
what I can think is:
select decode(max(case when col_1 is null then 1 else 0), 1, max(col_1), null)
from table_1.
Is there any better way? Since I need to do the aggregate function twice.
Thanks,
Kenny.
I need to find out the max. value of a column. But if there is a null in this column, I need to return null.
For example, the table Table_1 has column Col_1 with following rows:
1, 2, null.
If I issue SQL:
select max(col_1) from table_1,
Oracle will return 2.
But I want to return null.
Is it any way to do it?
what I can think is:
select decode(max(case when col_1 is null then 1 else 0), 1, max(col_1), null)
from table_1.
Is there any better way? Since I need to do the aggregate function twice.
Thanks,
Kenny.
0