last是聚合函数,context by返回的记录数跟组的长度一样,所以会重复产生多条记录。
context by可以用top 1来取最后一条记录,代码如下:
select top 1 last(date(EndDate)) as date,last(ShortTermLoan) as v from tbFactor where EndDate >= 2015.06.30,EndDate <= 2020.03.31,IfAdjusted == 2 and IfMerged == 1 and CompanyCode == 1518 context by InfoPublDate,CompanyCode,EndDate,IfAdjusted,IfMerged csort JSID asc