It's been a while since I deal with SQL. Let's say I have a table Transaction with the following columns: Company, Year, Value.
I want to create a resultset that sums the total value for each Company, but in one column I want 2015 and in other 2016.
Company | Total 2015 | Total 2016 |
Here's one option using
select company, sum(case when year = 2015 then value end) total2015, sum(case when year = 2016 then value end) total2016 from Transaction group by company