SELECT b.branch_code ,
'Q SEASON',
'TOTAL_FREE_UNITS'= SUM(PH.stock_units_free+PH.stock_units_Qc+PH.stock_units_IT+ph.stock_units_dmg),
'TOTAL_SP_VALUE' = SUM(PH.STOCK_SPVALUE_FREE+PH.STOCK_SPVALUE_QC+PH.STOCK_SPVALUE_IT+ph.stock_spvalue_dmg),
'TOTAL_CP_VALUE' = SUM(PH.STOCK_CPVALUE_FREE+PH.STOCK_CPVALUE_QC+PH.STOCK_CPVALUE_IT+ph.stock_cpvalue_dmg)
FROM PRODUCT_HISTORY ph, anal_level al,product_master pm ,branch b
WHERE ph.WEEK_SELECTOR = 1200123
and ph.product_id = pm.prod_id
and al.j_code = pm.j_code_link
and al.level_no = 4
and b.branch_id = ph.branch_id
and al.level1_desc in ('A/W 2008')
group by b.branch_code
union all
SELECT b.branch_code ,
'R SEASON',
'TOTAL_FREE_UNITS'= SUM(PH.stock_units_free+PH.stock_units_Qc+PH.stock_units_IT+ph.stock_units_dmg),
'TOTAL_SP_VALUE' = SUM(PH.STOCK_SPVALUE_FREE+PH.STOCK_SPVALUE_QC+PH.STOCK_SPVALUE_IT+ph.stock_spvalue_dmg),
'TOTAL_CP_VALUE' = SUM(PH.STOCK_CPVALUE_FREE+PH.STOCK_CPVALUE_QC+PH.STOCK_CPVALUE_IT+ph.stock_cpvalue_dmg)
FROM PRODUCT_HISTORY ph, anal_level al,product_master pm ,branch b
WHERE ph.WEEK_SELECTOR = 1200123
and ph.product_id = pm.prod_id
and al.j_code = pm.j_code_link
and al.level_no = 4
and b.branch_id = ph.branch_id
and al.level1_desc in ('S/S 2008')
group by b.branch_code
union all
SELECT b.branch_code ,
'ALL SEASON',
'TOTAL_FREE_UNITS'= SUM(PH.stock_units_free+PH.stock_units_Qc+PH.stock_units_IT+ph.stock_units_dmg),
'TOTAL_SP_VALUE' = SUM(PH.STOCK_SPVALUE_FREE+PH.STOCK_SPVALUE_QC+PH.STOCK_SPVALUE_IT+ph.stock_spvalue_dmg),
'TOTAL_CP_VALUE' = SUM(PH.STOCK_CPVALUE_FREE+PH.STOCK_CPVALUE_QC+PH.STOCK_CPVALUE_IT+ph.stock_cpvalue_dmg)
FROM PRODUCT_HISTORY ph, anal_level al,product_master pm ,branch b
WHERE ph.WEEK_SELECTOR = 1200123
and ph.product_id = pm.prod_id
and al.j_code = pm.j_code_link
and al.level_no = 4
and b.branch_id = ph.branch_id
and al.level1_desc not in ('S/S 2008','A/W 2008')
group by b.branch_code
|