如何将以下结果变为黄色?
我想找到上一年的最高分(不包括当前日期)和Name1和Parent1的分区
我已经尝试了以下没有给出所需结果的内容,它只返回正确分区的max,但是在所有日期之间.
@H_403_8@select [VDate],[Name1],[Parent1],[score],max(case when [VDate] > dateadd(year,-1,[VDate]) then [score] else null end) over (partition by [Name1],[Parent1]) AS MaxscoreInPrevIoUsLast12Months from [dbo].[Control]表数据:
@H_403_8@CREATE TABLE Control ([VDate] datetime,[Name1] varchar(10),[Parent1] varchar(10),[score] int); INSERT INTO Control ([VDate],[score]) VALUES ('2018-08-01 00:00:00','Name1','Parent1',80),('2018-07-01 00:00:00',85),('2018-06-01 00:00:00',90),('2017-09-01 00:00:00',100),('2017-08-01 00:00:00',95),('2017-07-01 00:00:00',70),('2018-08-01 00:00:00','Name2','Parent2',('2017-10-01 00:00:00',60),'Name3','Parent3',96),99),105) ;这适用于sql Server 2016