select cuh.organization_id, cuh.inventory_item_id,
cuh.period_start_date,
sum(cuh.quantity) as quantity
from csp_usage_histories cuh ,
csp_planning_parameters cpp
where cuh.History_Data_type = 1
and cpp.organization_id = cuh.organization_id
and cpp.secondary_inventory is null
and cpp.organization_type = 'W'
and cuh.transaction_type_id in (select transaction_type_id
from csp_usg_transaction_types cutt
where cutt.forecast_rule_id = cpp.forecast_rule_id)
group by cuh.organization_id,
cuh.inventory_item_id,
cuh.period_start_date