select sum(round(t.qty*t.unit_price,2)),t.dept_id from mm_operation_history t where t.operation_history_id in(
select max(t.operation_history_id)  from mm_operation_history t where t.bill_type in (1,14)
group by t.material_id, t.project_id ) 
and substr(t.operation_date,1,4) = '2006' 
and sutstr(t.operation_date,6,2) ='07' 
group by t.dept_id;