Guest User

Untitled

a guest
Mar 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. select
  2. bill_to_customer
  3. ,name
  4. ,city
  5. ,state
  6. ,zip
  7. ,sum(case when sort_date = '1-2017' then amount else null end) as jan_2017
  8. ,sum(case when sort_date = '2-2017' then amount else null end) as feb_2017
  9. ,sum(case when sort_date = '3-2017' then amount else null end) as mar_2017
  10. ,sum(case when sort_date = '4-2017' then amount else null end) as apr_2017
  11. ,sum(case when sort_date = '5-2017' then amount else null end) as may_2017
  12. ,sum(case when sort_date = '6-2017' then amount else null end) as jun_2017
  13. ,sum(case when sort_date = '7-2017' then amount else null end) as jul_2017
  14. ,sum(case when sort_date = '8-2017' then amount else null end) as aug_2017
  15. ,sum(case when sort_date = '9-2017' then amount else null end) as sept_2017
  16. ,sum(case when sort_date = '10-2017' then amount else null end) as oct_2017
  17. ,sum(case when sort_date = '11-2017' then amount else null end) as nov_2017
  18. ,sum(case when sort_date = '12-2017' then amount else null end) as dec_2017
  19.  
  20. from (
  21.  
  22. select
  23. bill_to_customer
  24. ,name
  25. ,upper(city) as city
  26. ,state
  27. ,postal_code as zip
  28. ,concat(month(trans_date),'-',year(trans_date)) as sort_date
  29. ,sum(amount) as amount
  30. from transactions_table
  31.  
  32. group by
  33. bill_to_customer
  34. ,name
  35. ,city
  36. ,state
  37. ,postal_code
  38. ,concat(month(trans_date),'-',year(trans_date))
  39. ,trans_date
  40. ) sub
  41. group by
  42. bill_to_customer
  43. ,name
  44. ,city
  45. ,state
  46. ,zip
  47.  
  48.  
  49. order by
  50. bill_to_customer
Add Comment
Please, Sign In to add comment