I am using the following PHP script to grab and alter data from a MySQL table and print the results in a HTML table. I was hoping to order the data in ascending order by the
You can calculate it in the query, and then use it in ORDER BY
.
$sql = "SELECT SUM(t.available_time) AS total_available_time,
SUM(t.chargeable_time) AS total_chargeable_time,
SUM(t.admin_time) AS total_admin_time,
SUM(t.new_business_time) AS total_new_business_time,
c.name AS companyName,
(SUM(t.chargeable_time) + SUM(t.admin_time) + SUM(t.new_business_time)) / SUM(t.available_time) * 100 AS utilization_percentage
FROM Timesheet t
LEFT JOIN fos_user u ON(u.id = t.user_id)
LEFT JOIN company c ON(c.id = u.company_id)
GROUP BY u.company_id
ORDER BY utilization_percentage";