SQL - value for the last date -


sounds easy guess of guys can't find solution due poor sql knowledge.

i have request:

  • first 3 columns margin can null

i want create column last application margin rule:

  • if margin null last value no null find.

screenshot here:

enter image description here

thanks lot

use isnull/coalesce , subquery:

select scope_enum_compete, margin, date_test,        isnull(margin, ( select top 1 margin                         dbo.tablename t2                         margin not null                          ,  t2.date_test < t1.date_test                          order date_test desc ))  [last applicable margin] dbo.tablename t1 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -