我正在尝试执行某些操作。我想让所有颜色填充值。但是,当我有空列时,我想用前一个非空列中的值填充它。
with cte as (
select '2019-11-12 16:01:55' as timestamp,null as owner_id,null as owner_assigneddate,null as lastmodifieddate union all
select '2019-11-12 19:03:18' as timestamp,39530934 as owner_id,'2019-11-12 19:03:18' as owner_assigneddate,'2019-11-12 19:03:18' as lastmodifieddate union all
select '2019-11-12 19:03:19' as timestamp,'2019-11-12 19:03:19' as lastmodifieddate union all
select '2019-11-12 19:03:20' as timestamp,'2019-11-12 19:03:20' as lastmodifieddate union all
select '2019-11-12 19:03:31' as timestamp,40320368 as owner_id,'2019-11-12 19:03:31' as owner_assigneddate,'2019-11-12 19:03:31' as lastmodifieddate union all
select '2019-11-12 19:03:33' as timestamp,'2019-11-12 19:03:33' as lastmodifieddate union all
select '2019-11-12 19:03:56' as timestamp,'2019-11-12 19:03:356' as lastmodifieddate)
select timestamp,owner_id,owner_assigneddate,lastmodifieddate,COALESCE(owner_id,LEAD(owner_id) OVER(ORDER BY timestamp DESC)) AS test_column
from cte order by timestamp asc
在上一个查询中,我已经设法将值仅放在下一行。
我想要做的是让所有列都基于上一行填充值。 第4行的值应为39530934,第7行的值应为40320368。 我想我在这里错过了一些东西,但是我不知道是什么。