Quotation Factor

Asked

Viewed 31 times

0

The SQL below returns me quotation value, I need to find the quotation day factor that boils down like this: SQL

SELECT SIMBOLO,
       CONVERT (VARCHAR(10),DATA,103) as DATA,
       FATOR 
FROM GCOTACAO  
WHERE SIMBOLO = 'CDI'


Símbolo     Data         Fator    Fator Dia
CDI         01/01/2014   10084    = fator - 1 = 0,0084
CDI         01/02/2014   10163    = Fator (10163 - 10084) - 1 
CDI         01/03/2014   10240    = Fator (10240 - 10163) - 1  

I appreciate all your help.

1 answer

1

Ronnie Von, try the following sql code:

SELECT SIMBOLO as [Símbolo], 
       convert (char(10), DATA, 103) as Data,
       FATOR as Fator,
       [Fator dia]= (FATOR - coalesce (lag (FATOR) over (order by DATA), 10000)) / 10000.
  from GCOTACAO;

He makes use of the function LAG() to obtain the FACTOR value of the previous line.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.