Ekrem Tapan

Ekrem Tapan

  • NA
  • 967
  • 81.2k

How to divide two values from the different row in SQL

Mar 28 2016 4:20 AM

hi everybody,
 
i have a this formula  
Quote change = (current month / previous month) * 100
 
my data stored in sql  table like that ;;
 
id --- date -                         data
1       2015/01/01             10
2       2015/02/01             15
3       2015/03/01             20
4       2015/04/01             15
.
.
.
10   2015/10/01             85
 
how can i implement this function on sql  
 for example current month is 2015/02/01
Quote change = (current month data / previous month data ) * 100
 Quote change =( 15/10)*100
 
then if now is   2015/01/01. because no any data before  2015/01/01 this i need to show 0 or - 
 
anybody can i help me  ?
 
 

Answers (2)