Search the Community
Showing results for tags 'average'.
-
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!
- 3 replies
-
- sql
- calculation
-
(and 1 more)
Tagged with:
-
First off...Hi everyone, I'm hoping you all can help. I'm working on a script that stores datetimes of users logging in and out of a system. I've found out how to get the time the user was logged in using the following code. $q = "SELECT * FROM VISITOR WHERE MONTH(timeIn)=MONTH(NOW()) ORDER BY id"; $monthsVisitors = mysql_query($q); while($row = mysql_fetch_array($monthsVisitors)) { $timeIn = $row['timeIn']; $timeOut = $row['timeOut']; $timeDiff = dateDiff($timeOut, $timeIn); } Assuming I store hundreds of entries in the "Visitor" table, with each row containing a "timeIn" and "timeOut". What would be the best way to get an average of "$timeDiff"?
-
Hello Everyone, Haven't been here in a while. This looks new and cool! Anyway, I have PHP output an array of numbers as an average and that worked fine. I got the number -.0111523. Which is exactly what I want. They only problem is that I need the number to look like this -.011. I tried to use the number format command, but that did not work. Just slapped a couple of zeros onto the end. Any suggestions? Thanks in advance!