我有下面的查询,它告诉我人们在给定的时间段内开始和结束。
select UserId,
cast(sum(CommissionPerc)/100 as numeric(2,1)) as PlacementCount,
datename(mm,startdate) + ' ' + 'Start' as DataType
from PlacementConsultants
group by userid, datename(mm,StartDate)
union
select UserId,
cast(sum(CommissionPerc)/100 as numeric(2,1)) as PlacementCount,
datename(mm,EndDate) + ' ' + 'End' as DataType
from Placements
group by userid, datename(mm,EndDate)
order by datatype
其输出如下:
791 4.0 May End
791 3.0 May Start
791 6.0 June End
791 2.0 June Start
791 1.0 July Start
但我也想有一列写为MonthName Change
例如
791 4.0 May End
791 3.0 May Start
791 -1.0 May Change
解决这个问题的最佳方法是什么?