asdkyd 2022-10-19 22:09 采纳率: 100%
浏览 240
已结题

sql 字段为空取上一行的值

如下表,样例所示,code与eff均有为空的情况,如何将为空赋值为上一条不为空的值,如需求所示

img

  • 写回答

12条回答 默认 最新

  • 一把编程的菜刀 2022-10-20 09:00
    关注

    SQ语句:

    SELECT time,(select code from table2 where code<>'' and time<=t.time order by time desc LIMIT 1) as code ,(select eff from table2 where eff<>'' and time<=t.time order by time desc LIMIT 1) as eff FROM table2 t
    
    

    结果如下:

    img

    测试用的数据如下:

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(11条)

报告相同问题?

问题事件

  • 系统已结题 11月2日
  • 已采纳回答 10月25日
  • 创建了问题 10月19日