I have a MySQL query which counts hours we have worked from the top five of our clients. This works fine, and I am plotting the data on a graph. What I am trying to achieve is a calculation within the query that returns a sixth result set which is the sum of all the hours which are not in the top five. i.e. An ‘Other’ result, so that the sum of all 6 results would equal the total of sum of projects.hours.
My query:
SELECT
SUM(projects.hours) AS total_hours
FROM projects
GROUP BY projects.companyID
ORDER BY total_hours DESC
LIMIT 5
Subtract total_hours from all_hours in your application.