Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- bill_to_customer
- ,name
- ,city
- ,state
- ,zip
- ,sum(case when sort_date = '1-2017' then amount else null end) as jan_2017
- ,sum(case when sort_date = '2-2017' then amount else null end) as feb_2017
- ,sum(case when sort_date = '3-2017' then amount else null end) as mar_2017
- ,sum(case when sort_date = '4-2017' then amount else null end) as apr_2017
- ,sum(case when sort_date = '5-2017' then amount else null end) as may_2017
- ,sum(case when sort_date = '6-2017' then amount else null end) as jun_2017
- ,sum(case when sort_date = '7-2017' then amount else null end) as jul_2017
- ,sum(case when sort_date = '8-2017' then amount else null end) as aug_2017
- ,sum(case when sort_date = '9-2017' then amount else null end) as sept_2017
- ,sum(case when sort_date = '10-2017' then amount else null end) as oct_2017
- ,sum(case when sort_date = '11-2017' then amount else null end) as nov_2017
- ,sum(case when sort_date = '12-2017' then amount else null end) as dec_2017
- from (
- select
- bill_to_customer
- ,name
- ,upper(city) as city
- ,state
- ,postal_code as zip
- ,concat(month(trans_date),'-',year(trans_date)) as sort_date
- ,sum(amount) as amount
- from transactions_table
- group by
- bill_to_customer
- ,name
- ,city
- ,state
- ,postal_code
- ,concat(month(trans_date),'-',year(trans_date))
- ,trans_date
- ) sub
- group by
- bill_to_customer
- ,name
- ,city
- ,state
- ,zip
- order by
- bill_to_customer
Add Comment
Please, Sign In to add comment