Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:59:16+00:00 2026-06-13T23:59:16+00:00

I have one table which is having three fields: Id, Creation Time, Fuel Level

  • 0

I have one table which is having three fields:

Id, Creation Time, Fuel Level

Every two minutes we are getting data and inserting to database.For generating a fuel credit/debit statement i want to get starting(Stating of the day) and ending(End of the Day) Fuel Level.Can anyone help to form a query to generate this report?

Search parameters will be date range.

Id=10;creation time =2019-02-15 16:32:59;Fuel Level =20

I created one sample schema here
http://sqlfiddle.com/#!2/76dd5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:59:17+00:00Added an answer on June 13, 2026 at 11:59 pm

    First, for a query that provides the change in fuel for each vehicle for each day, you can use the following SQL:

    SELECT trip_range.dt
         , trip_range.vehicle_id
         , st.fuel_content as start_fuel_content
         , en.fuel_content as end_fuel_content
         , en.fuel_content - st.fuel_content as fuel_change
      FROM (
    SELECT tp.vehicle_id, DATE(tp.creation_time) dt
         , MIN(tp.creation_time) start_time
         , MAX(tp.creation_time) end_time
      FROM trip_parameters tp
     GROUP BY tp.vehicle_id, DATE(tp.creation_time)
    ) as trip_range
      JOIN trip_parameters st
        ON st.vehicle_id = trip_range.vehicle_id
           AND st.creation_time = trip_range.start_time
      JOIN trip_parameters en
        ON en.vehicle_id = trip_range.vehicle_id
           AND en.creation_time = trip_range.end_time
     WHERE trip_range.dt BETWEEN '2012-11-08' AND '2012-11-09'
    

    If you want the Cumulative change in fuel across all vehicles for each day in the range, the following SQL should work:

    SELECT dt, SUM(fuel_change) as fuel_change
      FROM (
    SELECT trip_range.dt
         , en.fuel_content - st.fuel_content as fuel_change
      FROM (
    SELECT tp.vehicle_id, DATE(tp.creation_time) dt
         , MIN(tp.creation_time) start_time
         , MAX(tp.creation_time) end_time
      FROM trip_parameters tp
     GROUP BY tp.vehicle_id, DATE(tp.creation_time)
    ) as trip_range
      JOIN trip_parameters st
        ON st.vehicle_id = trip_range.vehicle_id
           AND st.creation_time = trip_range.start_time
      JOIN trip_parameters en
        ON en.vehicle_id = trip_range.vehicle_id
           AND en.creation_time = trip_range.end_time
     WHERE trip_range.dt BETWEEN '2012-11-08' AND '2012-11-09'
    ) change_by_vehicle
     GROUP BY 1
    

    Hope this helps!

    john…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in database that is having some fields one of which
I have one table, t1, which has fileds called userid, week and year fields.
I have two tables. One user table and one table in which results are
I have a table which needs to link one of three seperate tables, but
My table is having four fields in which two fields are unique. They are
I have a table which needs 2 fields. One will be a foreign key,
I have one table which contains events and dates, and another which contains the
I have one table TABLE_SUBJECT which contain a number of subjects. I need to
I have one database table which contains 8 columns. One of the columns is
I have to get data from Oracle Table in which I have one datefield

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.