Jump to content

Recommended Posts

I'm trying to make a diesel consumption scoreboard for the drivers in our company, but not sure how I can sort the drivers by average fuel consumption. I have two database tables, one for the members and one for the fuel data.

 

I'm using this sql query to calculate the average, but I would like to have some more information in the same query and also a way to easily sort the members by their average fuel consumption to complete the scoreboard.

 

SELECT 10 * SUM(liter) / (MAX(km) - MIN(km)) as AvgFuel FROM diesel WHERE diesel.dato >= '$dx' AND userid = ".$_COOKIE['userid'].";

 

In the diesel table there are information like km, liters, dates, locations etc.

 

How can I extend this query to have more information instead of having multiple queries ? (I'm a newbie)

 

Thanks for reading!

Link to comment
https://forums.phpfreaks.com/topic/288219-mysql-query-question/
Share on other sites

I've got this mysql query to calculate the average use of fuel for a member, but how can I get more info out from the database in the same query, such as username, kilometers, liters, dates etc ?

$result = mysqli_query($con,"SELECT 10 * SUM(liter) / (MAX(km) - MIN(km)) as AvgFuel FROM diesel WHERE userid = ".$_GET['uid']);
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.