Oracle SQL Pivot Query Example

select *
from
(
SELECT DISTINCT  dhcc.segment2 business_unit, dhcc.segment3 ACCOUNT,
                dhcc.segment4 dept, dhcc.segment5, fc.concatenated_segments,fpip.DEPRECIATION,fdp.Period_name
            FROM  fadeprn_temp fpip ,  fa_additions fa,
                fa_deprn_periods fdp,
                fa.fa_deprn_summary fds,
                fa_categories_b_kfv fc,
                fa_distribution_history dh,
                gl_code_combinations dhcc
          WHERE fa.asset_id = fds.asset_id
            AND fdp.period_counter = fds.period_counter
            AND dhcc.code_combination_id(+) = dh.code_combination_id
            AND fdp.book_type_code = fds.book_type_code
            AND fa.asset_category_id = fc.category_id
            AND dh.asset_id = fa.asset_id
--            and dh.asset_id =100562
--            and dhcc.segment2='251'
--            and dhcc.segment5='528502'
            AND fpip.asset_id = fa.asset_id
 ) src
pivot
(
  sum(DEPRECIATION)
  for Period_name in ('Jan-17','Feb-17','Mar-17','Apr-17','May-17','Jun-17','Jul-17','Aug-17','Sep-17','Oct-17','Nov-17','Dec-17')
) piv;

Comments

Popular posts from this blog

Oracle Shipping Network SQL Query

Oracle Ar Invoice Numbering Sequence alter to avoid missing in between by cache

Advance Supply Chaining Scripts - ASCP Full Pegging Concept Script