title: Get the difference in % of the last records
body: <p>I have the next table:</p>
  
  <pre><code>+----+-----------+------------+-----------+
  | ID | market_id | last_value | timestamp |
  +----+-----------+------------+-----------+
  | 1  |    1      |     10     |   1001    |
  | 2  |    1      |     15     |   1002    |
  | 3  |    1      |     25     |   1003    |
  | 4  |    1      |     30     |   1004    |
  | 5  |    1      |     05     |   1005    |
  +----+-----------+------------+-----------+
  </code></pre>
  
  <p>And my idea is something similar this:</p>
  
  <pre><code>SELECT id, market_id, last_value, timestamp from data_markets
  where from_unixtime(timestamp, '%d-%m-%Y %H:%m:%s') &gt;= DATE_FORMAT(NOW(),'%d-%m-%Y 00:00:00') and market_id = 1
  </code></pre>
  
  <p>With this, I get the all rows of today but i know as use join for get this:</p>
  
  <pre><code>+---+----------------------+--------------------+----------+
  | market_id |    change    |    total_change    |  is_down |
  +-----------+--------------+--------------------+----------+
  |     1     |     83.3%    |      -50.00%       |   true   |
  +-----------+--------------+--------------------+----------+
  </code></pre>
  
  <p>Explanation:</p>
  
  <ul>
  <li><p>Change: this value is the difference with the last row</p></li>
  <li><p>Total_change: this value is the difference of all rows in "24 hours"</p></li>
  <li><p>is down: it's possibly know if the value is increasing or decreasing respect the total change?</p></li>
  </ul>
  
  <p>Edit:</p>
  
  <p>I edit the example, in total_change I like the difference with all rows, but this is not possible can be the difference with the first row.</p>