var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Last year
I have a SQL server model with Bill and BillLine, where the second references the first
Bill(CodBill, Date, ...)
BillLine(CodBillLine,CodBill,Description, ..., Total)
What I want is a list of sum(total) grouped by month and description and also a list of last year sum(total).
Month | Description | Total this year |Total last year
1 | Water | 5.00 | 3.00
1 | Blood | 0.00 | 4.50
1 |Milk | 2.00 | 0.00
2 |Blood | 1.00 | 3.50
2 |Milk | 7.80 | 2.30
3 |... |... |...
12 |... |... |...
This is easy to do without the 4 th column using GROUP BY, but this column complicates all the thing. I was trying to do things with the PIVOT operator, but it was a useless effort.
Modify your query for the last 2 years like this
select Month, Description
, Total this year=sum(case when year... then total else 0 end)
, Total last year=sum(case when year... then total else 0 end)