I've got some problems with a pivot query (SQL Server).
The task is quite simple: for a person I have to collect it's income stats for every month in a year but every new month income is based on the previuos income plus the current month income
Just for example. Let a person have a 3k salary per month (for simplicity it's a constant) then a query result should be something like this:
Year | Jan | Feb | ... | Dec
2016 | 3k | 6k | ... | 36k
2015 | 3k | 6k | ... | 36k
...
A pseudo SQL query is:
select * from (
select
year(date) as year,
month(date) as month
salary,
from income
where personId = 'some id'
) as tmp
pivot (
sum(salary),
for month in ([1], [1..2], [1..3], ...)
) as pvt
The problem is there's no [1..2] expression in SQL. What's the way to perform such query using a standard SQL?