title: MySQL table value difference related to current date and previous date
body: <p>I have some tables that used to manage vehicle details. Related tables as follows:</p>
  
  <h1>store_item</h1>
  
  <pre><code>+---------+-----------+--------+
  | item_id | item_name | status |
  +---------+-----------+--------+
  |       1 | Diesel    |      1 |
  |       2 | Petrol    |      1 |
  +---------+-----------+--------+
  </code></pre>
  
  <h1>tbl_vehicle</h1>
  
  <pre><code>+------------+---------------+
  | vehicle_id | registered_no |
  +------------+---------------+
  |          1 | LE-7476       |
  |          2 | 270-0523      |
  +------------+---------------+
  </code></pre>
  
  <h1>tbl_direct_fuel</h1>
  
  <pre><code>+----------------+----------+---------+------------+------------+
  | direct_fuel_id | vehicle  | orderNo | issue_date | milo_meter |
  +----------------+----------+---------+------------+------------+
  |              1 | LE-7476  |  173072 | 2019-11-12 |    30,000  |
  |              2 | LE-7476  |  173069 | 2019-11-08 |    29,600  |
  |              3 | LE-7476  |  173059 | 2019-11-05 |    29,000  |
  |              4 | LE-7476  |  173055 | 2019-10-08 |    25,000  |
  |              5 | 270-0523 |  173068 | 2019-11-02 |    10,000  |
  |              6 | 270-0523 |  173067 | 2019-10-02 |     8,500  |
  +----------------+----------+---------+------------+------------+
  </code></pre>
  
  <h1>tbl_direct_fuel_details</h1>
  
  <pre><code>+------------------------+----------------+------+----------+------------+
  | direct_fuel_details_id | direct_fuel_id | item | fuel_qty | fuel_price |
  +------------------------+----------------+------+----------+------------+
  |                    100 |              1 |    1 |       20 |        105 |
  |                    101 |              2 |    1 |       15 |        105 |
  |                    102 |              3 |    1 |       12 |        105 |
  |                    103 |              4 |    2 |       50 |        165 |
  |                    104 |              5 |    1 |       25 |        100 |
  |                    105 |              6 |    2 |       18 |        165 |
  +------------------------+----------------+------+----------+------------+
  </code></pre>
  
  <h1>Desired Output</h1>
  
  <p>I want to get no_of_kms, vs issued fuel quantities using issue_date &amp; milo_meter (current milo_meter - previous milo_meter). The output as follows :</p>
  
  <pre><code>+----------+-----------+
  | vehicle  | no_of_kms |
  +----------+-----------+
  | LE-7476  |      400  |
  | LE-7476  |      600  |
  | LE-7476  |    4,000  |
  | 270-0523 |     1500  |
  +----------+-----------+
  </code></pre>
  
  <p>I used the following query :</p>
  
  <pre><code>select v1.registered_no as vehicle, si.item_name as fuel, df.milo_meter - df.milo_meter  as no_of_kms
  from (select dfd.item, sum(dfd.fuel_qty) AS qty
        from tbl_direct_fuel df
        join tbl_direct_fuel_details dfd on df.direct_fuel_id = dfd.direct_fuel_id
        join tbl_vehicle v1 on df.vehicle = v1.vehicle_id
        where df.status = 1
        group by registered_no) dfd
  join store_item si on dfd.item = si.item_id
  join (select item, sum(dfd.fuel_qty) AS fuel_qty
        from tbl_direct_fuel_details
        group by item) dfd on si.item_id=dfd.item
  </code></pre>
  
  <p>But the above query didn't working fine. What may be going wrong ? Can anyone help me ?</p>