I think you want to do a join with 2 group bys
The Join starts out
SELECT * FROM costcodes, projects where costcode.id=procect.costcodeid
You want to group the projects together
SELECT * FROM costcodes, projects where costcode.id=procect.costcodeid
GROUP BY project.id
You also then want go group the costs together
GROUP BY project.id, costcode.id
You dont want all the fileds, but You want
project.id, costcode.id
and some math--
How many times the costcode id occurs tiimes the cost amount
COUNT(costcode.id) * costcode.amount
SO I think it's:
SELECT project.id,
costcode.id,
COUNT(costcode.id) * costcode.amount
FROM costcodes, projects
WHERE costcode.id=procect.costcodeid
GROUP BY project.id, costcode.id