Jump to content

mysql query question


Aero77

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']);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.