我需要显示当前年份和上一年迄今为止的结果。理想情况下,我希望结果看起来像
ID|CYTD|PYTD
# |Sum |Sum
我的查询如下所示。问题是我如何设置与当年的行匹配相同的 id 的位置。
select Table.ID,
SUM(Table.Column) as CYTD,
(select SUM(Table.Column) from Table
where Table.Id = ?? and Table.Year between Prev and Current
group by Table.Id) as PYTD
Where Table.Year between Current and Future
group by Table.Id