select greatest(-99, 0, 73) --73
select greatest(-99, 0, 73, null) --null
select greatest(-99, 0, 73, 'string') --null
select greatest('2022-01-01','2022-06-01','2022-06-09') --2022-06-09
select customer_id,
greatest(income_2016,income_2017,income_2018,income_2019,income_2020,income_2021) income
from
(
select customer_id,
if(income_2016 is null,-9999999,income_2016) income_2016,
if(income_2017 is null,-9999999,income_2017) income_2017,
if(income_2018 is null,-9999999,income_2018) income_2018,
if(income_2019 is null,-9999999,income_2019) income_2019,
if(income_2020 is null,-9999999,income_2020) income_2020,
if(income_2021 is null,-9999999,income_2021) income_2021
from table
) a;
select least(-99, 0, 73) -- -99
select least(-99, 0, 73, null) --null
select least(-99, 0, 73, 'string') --null
select least('2022-01-01','2022-06-01','2022-06-09') -- 2022-01-01
参考:https://blog.csdn.net/szdxltt/article/details/125204552