Oracle > Union and group by

 select
 eff_date,
 sum(number_of_items)
 from
 (select
    to_char(effective_report_date,'mmyyyy') as eff_date,
    count(*) number_of_items
    from dm1
    where to_char(effective_report_date,'mmyyyy') = '082004'
    group by to_char(effective_report_date,'mmyyyy')
  union all
    select
    to_char(effective_report_date,'mmyyyy') as eff_date,
    sum( number_of_items)
    from dm2
    where to_char(effective_report_date,'mmyyyy') = '082004'
    group by to_char(effective_report_date,'mmyyyy')
 )
 group by eff_date

Tags: ,

Leave a Reply