如何删除END TIME(第3列)和下一个开始时间(第2列)之间的所有NULL值(时间间隔)?
谢谢!
表示例:
NULL 06:00:00.0000000 NULL
NULL 06:15:00.0000000 NULL
NULL 06:30:00.0000000 NULL
NULL 06:45:00.0000000 NULL
NULL 07:00:00.0000000 NULL
NULL 07:15:00.0000000 NULL
NULL 07:30:00.0000000 NULL
07:30:00.0000000 08:30:00.0000000
NULL 07:45:00.0000000 NULL
NULL 08:00:00.0000000 NULL
NULL 08:15:00.0000000 NULL
NULL 08:30:00.0000000 NULL
08:30:00.0000000 09:00:00.0000000
NULL 08:45:00.0000000 NULL
NULL 09:00:00.0000000 NULL
09:00:00.0000000 09:30:00.0000000
NULL 09:15:00.0000000 NULL
NULL 09:30:00.0000000 NULL
09:30:00.0000000 09:45:00.0000000
答案 0 :(得分:0)
您似乎只想保留最初的NULL
值。所以,像:
select t.*
from t
where t.endtime is not null or
t.endtime < (select min(t2.endtime) from t t2);
答案 1 :(得分:0)
请查看本文如何获取sql server中的上一行,然后检查prev值和当前值是否为null: https://blog.sqlauthority.com/2013/09/22/sql-server-how-to-access-the-previous-row-and-next-row-value-in-select-statement/
答案 2 :(得分:-1)
DELETE FROM table WHERE id BETWEEN 79 AND 296