date1 date2
7月15 7月15
7月16 null
7月17 null
7月18 7月18
7月19 null
7月20 null
7月21 null
7月22 7月22
將上列資料中為null的資料更新為臨近時間的最小時間
例如 7月16及7月17對應的兩個null更新為7月15
7月19 7月20 7月21 對應的null更新為7月18
uj5u.com熱心網友回復:
已解決case when date2 is null
then (select max(date2) as maxtime from table1 where date2<date1)
else date2
end as date2
當date2為null時
從表中獲取小于 (當date2為null時的date1)的最大date2
例如當 date1=7月17時 date2 is null
select max(date2) from table1 where date1<'7月17'
注:上面的日期格式不規范,正常應為'2020-07-17'
uj5u.com熱心網友回復:
UP MARK轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/10261.html
標籤:MySQL
上一篇:DB2存盤程序誤刪如何恢復
