title: Calculate the percentage of change in price with reflected to previous observation, group by price type?
body: <p>I am trying to calculate daily percentage change in price with reflected to previous observation by price type.</p>
  
  <p>When I run this query, it seems to calculate the percentage change but the calculation is done from one price type to another. </p>
  
  <p>I want to calculate the percentage change in price by pricetypeID. </p>
  
  <p>Do you have any idea how to implement it? Any tip would be very appreciated!</p>
  
  <pre><code>select priceTypeID, date, price,
       if(@last_entry = 0, 0, round(((price - @last_entry) / @last_entry) * 100,2)) "percentageChange",
       @last_entry := price
       from
       (select @last_entry := 0) x,
       (select date, `t`.price, `t`.priceTypeID
       from   `t`
       order by `t`.priceTypeID, `t`.date asc) y;
  order by date ASC
  </code></pre>
  
  <p>Example data is here: 
  <a href="https://www.dropbox.com/s/fq57pks2d28i1j4/example.csv?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/fq57pks2d28i1j4/example.csv?dl=0</a></p>