How to get the minimum date of several columns, excluding nulls?
insert into table (col1, col2, col3, col4) values ('2015-01-01','2014-01-01','2013-01-01', NULL )
I am looking for a function like this:
select least_date(col1, col2, col3, col4) from table
result: '2013-01-01'
How can I get the minimum date of several columns, excluding nulls?
0
Comments
You could do this:
assuming that you'll have some valid dates in the columns.
If you'd like it to be a little bit more natural to write, you could create a UDF that ignores the NULLs and computes the minimum for each row.
--Sharon