After looking back on this and I understand a little morewhats going on, I SUPPOSE you can achieve you desired result from your temp table already made... Not best practice though, IMO.
Non detailed:
Code:
select
company,
sum(job_amount) as job_amount_sum,
sum(labor_amount) as labor_amount_sum,
sum(material_amount) as material_amount_sum,
sum(balance_amount) as balance_amount_sum
from
jobs
group by
company
order by company asc
Detailed:
Code:
select
company,
concat(jobnum, ' - ', description),
sum(job_amount) as job_amount_sum,
sum(labor_amount) as labor_amount_sum,
sum(material_amount) as material_amount_sum,
sum(balance_amount) as balance_amount_sum
from
jobs
group by
company,
concat(jobnum, ' - ', description),
order by company asc
To use the detail view you can simply use something like excel to make a pivot table using company name... or get into a simple PHP iteration to display results in your desired fashion. NOTE: this will sum() up records with the same jobnum, ensure you dont have duplicate jobnums. If there are no duplicate jobnums, you can remove all aggregate functions from the second query.
Bookmarks