简体   繁体   English

SQL:如何获取下一个非空值

[英]SQL: How to get the next not null value

SQL to get next not null value in column SQL获取列中的下一个非空值

I am trying to use this solution but I am totally new in SQL and could not understand我正在尝试使用此解决方案,但我对 SQL 完全陌生并且无法理解

select t., t2.orig as newval 
from @t t 
outer apply (select top 1 t2. from @t t2 where t2.id >= t.id 
and t2.orig is not null order by t2.id ) t2;

What is t.*? t.* 是什么? Where Comes the value t2 and id, as I dont see it in the Question?哪里来的值 t2 和 id,因为我没有在问题中看到它?

t2 is an alias. t2 是别名。 Where it's written写在哪里

from @t t2

that is giving the alias of t2 to the table @t so it can be referenced by either.这将 t2 的别名赋予表 @t 以便它可以被任何一个引用。 t2.id is just referencing the id column specifically from the instance of @t you've named t2. t2.id 只是从您命名为 t2 的 @t 实例中专门引用了 id 列。 You need to reference it like this whenever you've joined with tables that have the same column name, because without it the code doesn't know from which table you're trying to make reference to.每当您加入具有相同列名的表时,您都需要像这样引用它,因为没有它,代码不知道您要从哪个表进行引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM