SELECT
b.member_id,
CASE when c.cal_dt >= to_date('2006-01-01','yyyy-mm-dd')
and c.cal_dt < to_date('2006-02-01','yyyy-mm-dd')
THEN '1'
when c.cal_dt >= to_date('2006-02-01','yyyy-mm-dd')
and c.cal_dt < to_date('2006-03-01','yyyy-mm-dd')
THEN '2'
ELSE '3'
end as flag ,
sum(a.value_amt) as total_spend
FROM
master.f_purchase_category b,
master.d_date c
WHERE b.d_trans_date_key=c.d_date_key
and c.cal_dt >= to_date ('2006-01-01','yyyy-mm-dd')
and c.cal_dt < to_date ('2006-03-20','yyyy-mm-dd')
group by a.member_id, flag
b.member_id,
CASE when c.cal_dt >= to_date('2006-01-01','yyyy-mm-dd')
and c.cal_dt < to_date('2006-02-01','yyyy-mm-dd')
THEN '1'
when c.cal_dt >= to_date('2006-02-01','yyyy-mm-dd')
and c.cal_dt < to_date('2006-03-01','yyyy-mm-dd')
THEN '2'
ELSE '3'
end as flag ,
sum(a.value_amt) as total_spend
FROM
master.f_purchase_category b,
master.d_date c
WHERE b.d_trans_date_key=c.d_date_key
and c.cal_dt >= to_date ('2006-01-01','yyyy-mm-dd')
and c.cal_dt < to_date ('2006-03-20','yyyy-mm-dd')
group by a.member_id, flag